Link to home
Start Free TrialLog in
Avatar of akashsuresh
akashsureshFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to increase font size of labels in JPanel without using UpdateUI?

I want to increase the font of labels on a JPanel using a slider.Right now I am using UpdateUI each time the slider is moved to refresh the entire panel.However I lose all the changes done,for example if a label is clicked it changes to blue.When I move the slider,it resets everything to the start.How to avoid this?
Avatar of ksivananth
ksivananth
Flag of United States of America image

can u post your code?
Avatar of zzynx
private static void applyLabelsFontSize(int fontSize) {
    UIDefaults uiDefaults = UIManager.getDefaults();
    Font font = uiDefaults.getFont("Label.font");
    if (font != null) {
      uiDefaults.put("Label.font", new FontUIResource(font.deriveFont(font.getStyle(), fontSize)));
    }
    SwingUtilities.updateComponentTreeUI(<the 'root' window of your app>);
}
Avatar of akashsuresh

ASKER

Ok now under a JFrame I have one panel and above that I have a Tabbed Pane.Now I want to increase the font of only the labels of the tabbedpane,how do I do that?
I mean for example if I have a tabbedpane under the frame and I want to change the font size of the labels of only one panel,how do I do it.
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.