How do I get the default font for Swing JTabbedPane labels?

后端 未结 6 674
無奈伤痛
無奈伤痛 2020-12-18 23:41

Does the text in Swing components have a default font? In particular, what about tab labels on JTabbedPanes?

I\'m working on a mock-up of a GUI made wi

6条回答
  •  有刺的猬
    2020-12-18 23:49

    Based on the answer of Reverend Gonzo, this piece of code lets you know what keys are in the UIDefaults. As the keys are self-explanatory, you know what key you can use. I had to know the key for the JTextField font, for example, and could only find it this way.

    Set keys = UIManager.getDefaults().keySet();
    for (Object key : keys) {
         if (key instanceof String && ((String) key).contains("font")) {
              System.out.println(key + "=" + UIManager.getDefaults().get(key));
         }
    }
    
    
    

    If you're looking for a font, in your case, just cast the key to a String and check whether it contains the word "font". This way you narrow the set of keys you have potential interest for.

    I got a list

    • Menu.font=...
    • TextField.font=...
    • RadioButtonMenuItem.font=...
    • ToolTip.font=...
    • TitledBorder.font=...
    • ...
    • TabbedPane.font=...
    • ...

    And thus you would need to pick TabbedPane.font.

    提交回复
    热议问题