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

三世轮回 提交于 2019-11-28 03:13:01

问题


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 with Swing and want it to blend it with a screen image I grabbed of a Swing app.


回答1:


It depends on the Look and Feel. If it's an application you've written, get the values from UIManager.getDefaults().getFont("TabbedPane.font")




回答2:


The UIManager Defaults shows what the values are for all properties for all components (including "TabbedPane.font").




回答3:


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<Object> 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.




回答4:


It may depend on the 'Look and Feel' you are using, but for me Swing's default font is

DejaVu Sans - Plain

For most components the font size defaults to around 12 or 13




回答5:


It looks like it's Arial. That's what Identifont tells me and it looks right.




回答6:


The Java GUI default font is "Helvetica", bold size 9, color gray.



来源:https://stackoverflow.com/questions/1434201/how-do-i-get-the-default-font-for-swing-jtabbedpane-labels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!