【问题标题】:Java nimbus - color differs sometimes even if It is same codeJava nimbus - 即使是相同的代码,颜色有时也会有所不同
【发布时间】:2014-09-12 11:14:00
【问题描述】:

我正在使用 Nimbus L&F、JDK 1.7 和 Netbeans 8.0。

我应该自定义 Nimbus。但是,当我在不更改任何代码的情况下运行我的项目时,我通过 UIManager 设置的一些颜色正在改变。

这是我设置 Nimbus 的地方;

try {
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (Exception e) {
            System.err.println("Some error");
}

这是我的画家示例(darkpainter 与 Color.Gray 相同,而不是 Color.orange);

Painter orangePainter = new Painter() {

            @Override
            public void paint(Graphics2D g, Object object, int width, int height) {
                g.setColor(Color.Orange);
                g.fillRect(0, 0, width, height);
            }
        };

我正在使用这些代码进行自定义;

UIManager.put("control", Color.gray);
UIManager.put("nimbusBlueGrey", Color.gray.darker());
UIManager.put("nimbusBorder", Color.orange);
UIManager.put("TabbedPane:TabbedPaneTab[Disabled].backgroundPainter", darkpainter);
UIManager.put("TabbedPane:TabbedPaneTab[Disabled+Selected].backgroundPainter", orangePainter);
UIManager.put("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter", darkpainter);
UIManager.put("TabbedPane:TabbedPaneTab[Selected].backgroundPainter", orangePainter);

我找不到问题。 我尝试使用 JDK 1.8 和 Netbeans 7.3。我也尝试直接从控制台运行,但同样的问题。 感谢您的帮助。

【问题讨论】:

    标签: java netbeans customization nimbus


    【解决方案1】:

    自从我使用 Nimbus 已经有一段时间了,但如果我没记错的话,大多数 Nimbus 元素都不是那么容易使用标准方法覆盖的。

    我强烈建议您查看 Nimbus 特定教程或指南,了解如何正确覆盖颜色/字体/等。

    stackOverflow 上另一个问题的答案包含与您相关的信息,您应该阅读它以获取更多信息。

    Override Swing Nimbus L&F primary color per component instance

    【讨论】:

      猜你喜欢
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-15
      • 2016-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多