Java 如何获得 Swing JTabbedPane 标签的默认字体?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1434201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 12:14:02  来源:igfitidea点击:

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

javauser-interfaceswinglook-and-feel

提问by Paul Reiners

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

Swing 组件中的文本是否具有默认字体?特别是,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.

我正在制作一个用 Swing 制作的 GUI 模型,并希望它与我从 Swing 应用程序中抓取的屏幕图像混合。

采纳答案by Reverend Gonzo

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

这取决于外观和感觉。如果它是您编写的应用程序,请从UIManager.getDefaults().getFont("TabbedPane.font")

回答by Tom Neyland

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

这可能取决于您使用的“外观和感觉”,但对我来说 Swing 的默认字体是

DejaVu Sans - Plain

DejaVu Sans - 普通

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

对于大多数组件,字体大小默认为 12 或 13 左右

回答by Paul Reiners

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

好像是阿里的。这就是Identifont告诉我的,它看起来是对的。

回答by camickr

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

UIManager的默认显示什么值是所有组件(包括“TabbedPane.font”)的所有属性。

回答by Timmos

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.

根据 Reverend Gonzo 的回答,这段代码让您知道 UIDefaults 中有哪些键。由于键是不言自明的,因此您知道可以使用什么键。例如,我必须知道 JTextField 字体的键,并且只能通过这种方式找到它。

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=...
  • ...
  • Menu.font=...
  • TextField.font=...
  • RadioButtonMenuItem.font=...
  • 工具提示.font=...
  • TitledBorder.font=...
  • ...
  • TabbedPane.font=...
  • ...

And thus you would need to pick TabbedPane.font.

因此,您需要选择 TabbedPane.font。

回答by JavaLicious

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

Java GUI 默认字体为“Helvetica”,粗体大小为 9,颜色为灰色。