• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

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?
0
akashsuresh
Asked:
akashsuresh
1 Solution
 
ksivananthCommented:
can u post your code?
0
 
zzynxSoftware engineerCommented:
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>);
}
0
 
akashsureshAuthor Commented:
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?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
akashsureshAuthor Commented:
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.
0
 
zzynxSoftware engineerCommented:
Labels accept html code as their text. So code like

label.setText("<html>Your<b>text</b></html>");

Open in new window


works. You could pass the correct html code for setting the font size.
0
 
DhaestCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now