| Author |
Change font style to Bold, Swing, all components
|
yoga nina
Greenhorn
Joined: Aug 13, 2011
Posts: 5
|
|
I have to code menu buttons to change the font style between Normal and Bold. The only sample code in my text only references one label whereas I have to code it so all the components, text, dialog, numbers etc change when button selected. The code is:
if (mnuBold.isSelected()) {
java.awt.Font oldFont = lblOutput.getFont();
java.awt.Font newFont = new java.awt.Font(oldFont.getName(), java.awt.Font.BOLD, oldFont.getSize()):
lblOutput.setFont(newFont);
}
How can I change this code so that it will apply to all the components and not just the lblOutput?
Is there better code to accomplish this?
Thanks for your help.
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4167
|
|
How can I change this code so that it will apply to all the components and not just the lblOutput?
Iterate recursively over all the components in the top level container. Or you could use that appropriate utility method of my SwingUtils class tp get a List of all children that are JComponent subclasses.
Is there better code to accomplish this?
Also, use imports so you don't have to clutter up the code with fully qualified class names.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
 |
|
|
subject: Change font style to Bold, Swing, all components
|
|
|