aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Change font style to Bold, Swing, all components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Change font style to Bold, Swing, all components" Watch "Change font style to Bold, Swing, all components" New topic
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: 4664
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change font style to Bold, Swing, all components