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

Posted on 2012-09-02
Last Modified: 2013-01-25
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?
Question by:akashsuresh
    LVL 26

    Expert Comment

    can u post your code?
    LVL 37

    Expert Comment

    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>);
    LVL 1

    Author Comment

    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?
    LVL 1

    Author Comment

    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.
    LVL 37

    Accepted Solution

    Labels accept html code as their text. So code like


    Open in new window

    works. You could pass the correct html code for setting the font size.
    LVL 53

    Expert Comment

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    EvenOdd challenge 10 68
    Python multiple IF statements 4 59
    Understanding websocket example in spring 1 20
    Change to event 1 49
    Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now