java - 更改 JOptionPane.showInputDialog 中默认字体的过程给出了混合结果

标签 java fonts

在 70 岁时,我决定学习 Java,我必须说这项任务有时给我带来了很多挫败感。为了显示可供选择的项目列表,我决定使用 JOptionFrame 类的 showInputDialog 选项,我发现每当通过调用 UIManager 将错误字体更改为等宽字体时,该选项都可以完美对齐,如下所示: UIManager.put("List.font", new Font( "monospaced",Font.PLAIN,14));

问题是,每当我在我认为所谓的父框架中插入列表时,字体就会返回到默认值,这将不再起作用。我可以毫无问题地插入其他对象,但不能插入列表。我的问题是:我做错了什么?相关代码如下。

UIManager.put("List.font", new Font( "monospaced",Font.PLAIN,14));

String input = (String) JOptionPane.showInputDialog(null, 
        "World Exchanges",
        "Please select one", JOptionPane.QUESTION_MESSAGE, null, 
        choices, choices[0]); // Initial choice

最佳答案

我怀疑这是外观和感觉缓存行为不一致的结果。 UIManager 的 javadoc 是这样说的:

The set of defaults a particular look and feel supports is defined and documented by that look and feel. In addition, each look and feel, or ComponentUI provided by a look and feel, may access the defaults at different times in their life cycle. Some look and feels may aggressively look up defaults, so that changing a default may not have an effect after installing the look and feel. Other look and feels may lazily access defaults so that a change to the defaults may effect an existing look and feel. Finally, other look and feels might not configure themselves from the defaults table in any way. None-the-less it is usually the case that a look and feel expects certain defaults, so that in general a ComponentUI provided by one look and feel will not work with another look and feel.

我的建议(基于此)是调用此电话:

UIManager.put("List.font", new Font("monospaced", Font.PLAIN,14));

选择外观之后(如果您这样做),实例化任何 Swing 组件之前。

关于java - 更改 JOptionPane.showInputDialog 中默认字体的过程给出了混合结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43443801/

相关文章:

Java NIO HTTP 服务器和浏览器

java - h2o 基本解析文件

java - IDEA 在 JAR 中创建空的命名文件夹

java - 我为 Rubymine 创建的插件不兼容

Java Swing 练习 - 无法访问变量,不知道为什么

cocoa - NSAttributedString drawAtPoint 和 drawInRect - 差异

java - iText 字体策略

ios - 消除移动 Safari textarea 小部件中的自动缩放?

java - Libgdx 在我填写 .fnt 时加载寻找 .png 的字体

silverlight - silverlight2 应用程序中的模糊字体