Question

I am am attempting to create a GUI to assist in playing a tabletop simulation game in Java. As part of that, I would need labels or some other form of text display that allows for a large font size for clarity. Is there a way to manipulate the size of text in a JLabel, or if not, is there another element that would allow me to do so. I could use images for each case, but I would rather not.

Was it helpful?

Solution

You can use the .setFont method in a label, like so:

label = new JLabel("A label");
label.setFont(new Font("Serif", Font.PLAIN, 14));

OTHER TIPS

There are a number of ways you might achieve this based on what it is you ultimately want to achieve.

For example, you could use...

Font font = ...
AffineTransformation at = AffineTransformation.getScaleInstance(2, 2);
font = font.deriveFont(at);

Which will double the font size...Don't forget to assign the resulting Font to the component you want to change ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top