It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Sizing up all my components! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Sizing up all my components!" Watch "Sizing up all my components!" New topic

Sizing up all my components!

Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
I have dozens and dozens of JLabels and JTextFields and JTable. And now I want to every thing have a bigger font. How do I go about doing this? I was wondering how to change color on a JLabel once, and someone proposed to use HTML tags around my string, which worked fine. But I really need a more efficient way this time or this is going to take forever!
Let me know!
maggie woo
Ranch Hand

Joined: Dec 18, 2003
Posts: 35
well, for the JLabel anyhow, maybe extend it to create a JLabel that has the attributes you want and make all your JLabels one of those objects. (e.g., MyBlueTahomaLabel, MyBlueTahomaCheckBox, etc).
or make a "label adder" helper method that (if called) will add the label in the desired font and color (e.g., addBlueTahomaLabel(String text, ...)). this works best if your layout is fairly straightforward and each label can be added given the passed in parameters. like you might pass in x/y coordinates or gridbagconstraints. along those lines, create "adder" methods for other types of components.
just to screw around. there's probably a more elegant way of getting what you want done...
if you needed to put html tags around all the labels for some reason, you could override whatever method it is that renders the text and always nest the text value inside the html tags so that the same code does the same work in the same place for all the same type of component.
or you could write a little engine that iterates over all the visible components in your container(s) and sets the font and color (if setters are available).
just some ideas to pick from. probably plenty of others too..
I agree. Here's the link:
subject: Sizing up all my components!
It's not a secret anymore!