Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 664701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:37:42+00:00 2026-05-13T23:37:42+00:00

I’m updating a Java Swing application to support the user switching the app’s font

  • 0

I’m updating a Java Swing application to support the user switching the app’s font from normal size to a larger size (so the user can switch between the two sizes at runtime). One problem I’m having is with a JTree that uses HTML for the tree nodes to underline the text in some nodes (the HTML is just embedded in the JLabel of each tree node). One extra thing to know about the nodes is that they’re a custom component, adding a JCheckBox in front of each JLabel.

The problem is that once the JTree is visible, increasing the font size causes the nodes (containing underlined text) to not resize. The HTML for those nodes seems to prevent the node from becoming wider, so when the font changes, the text becomes truncated.

I think my options are to either: 1) use another approach to make the text underlined, since removing the HTML from the JLabel causes it to resize properly when the font size changes, or 2) keep the HTML formatting and somehow force the JTree/JLabels to resize when the font size is updated (possibly by firing a property change event?).

The code already calls SwingUtilities.updateComponentTreeUI() on the parent JFrame when the font size gets updated.

EDIT: The method used to change the font in the application is explained here.

Any help would be greatly appreciated. Thanks in advance!

-Mike

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:37:43+00:00Added an answer on May 13, 2026 at 11:37 pm

    I cannot recreate the problem you describe. Here is a test program that works for me on JavaSE 6:

    public class JTreeFontResize {
        private static JTree tree;
        private static JFrame frame;
    
        public static void main(String[] args) throws InterruptedException,
                InvocationTargetException {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    tree = new JTree(new Object[] { "One (plain)",
                            "<html><u>Two (HTML)", "<html>Three (HTML)" });
                    frame = new JFrame("Tree Font Resize");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setBounds(100, 100, 300, 300);
                    frame.add(tree);
                    frame.setVisible(true);
                }
            });
    
            Thread.sleep(2000);
            changeFontSize(20);
    
            Thread.sleep(2000);
            changeFontSize(30);
    
            Thread.sleep(2000);
            changeFontSize(12);
        }
    
        private static void changeFontSize(final int size) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    Font font = new Font("Vernanda", Font.PLAIN, size);
                    FontUIResource fontResource = new FontUIResource(font);
                    Enumeration<Object> keys = UIManager.getDefaults().keys();
                    while (keys.hasMoreElements()) {
                        Object key = keys.nextElement();
                        Object value = UIManager.get(key);
                        if (value instanceof FontUIResource) {
                            UIManager.put(key, fontResource);
                        }
                    }
                    SwingUtilities.updateComponentTreeUI(frame);
                }
            });
        }
    }
    

    If the above works for you then maybe you should post a cut down version of your problematic code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Spring 3 is not an implementation of JSR-311. Maybe that's… May 14, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer Not without the help of a browser-specific extension I think,… May 14, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer Finally, I used LinkedList Public Sub Add(ByVal item As T)… May 14, 2026 at 4:39 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.