【问题标题】:JOptionPane has no effect when look and feel set设置外观和感觉时,JOptionPane 无效
【发布时间】:2013-06-20 10:05:47
【问题描述】:

我在下面设置了主类的外观。

基类代码:

 static
{
    try
    {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    }
    catch (Exception exception)
    {
        logger.error("Error setting look and feel!", exception);
    }
}

子类代码:

   int result = JOptionPane.showOptionDialog(panel,
            message,
            "",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            formattedOptions,
            formattedOptions[0]);

窗口外观没有设置为 JOptionPane 的窗口,而是显示 java 默认外观。

你能帮帮我吗?

【问题讨论】:

  • 仅适用于JOptionPane,其他组件的外观和感觉是否正确
  • 是所有其他组件的行为都与主类中的设置外观相同。但 JOPtion 不是?
  • 在调用 JOptionPane 之前 是否设置了外观?
  • 是的,我也尝试以下方式...尝试 { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception exception) { } int result = JOptionPane.showOptionDialog(panel, message, "", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, formattedOptions, formattedOptions[0]);
  • 您能否发布和 [SSCCE](www.sscce.org) 不仅仅是代码片段?

标签: java windows swing look-and-feel


【解决方案1】:

这很可能与时间有关。尝试使用 vm arg 设置 laf:

-Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel

【讨论】:

    猜你喜欢
    • 2014-03-19
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多