gpt4 book ai didi

java - Nimbus Look&Feel refresh Painter

转载 作者:行者123 更新时间:2023-11-29 05:55:19 24 4
gpt4 key购买 nike

我在我的挥杆应用程序中使用 Nimbus 外观。

我设置了 UIDefaults 的主要和次要属性的外观和感觉。
颜色是对的。现在我有一个问题,组件的画家使用颜色,这些颜色是在更新颜色主题之前定义的。

有没有办法更新所有组件的画家以使用新颜色,还是我需要为每个属性实现一个自定义画家?

我已经调用 SwingUtilities.updateComponentTreeUI(window)UIDefaults 中设置属性后.

编辑:

以下代码设置整个应用程序的 L&F:


try {
for( LookAndFeelInfo info : UIManager.getInstalledLookAndFeels() ) {
if( "Nimbus".equals( info.getName() ) ) {
UIManager.setLookAndFeel(info.getClassName());
customizeNimbusLaF();
SwingUtilities.updateComponentTreeUI( appWindow );
break;
}
}
}
catch( Exception e ) {
LogUtility.warning( "cannot set application look and feel" );
LogUtility.warning( e.getMessage() );
}

代码做了,它应该做什么(设置 Nimbus 的外观和感觉)。
问题是, Painters的菜单和其他组件使用旧颜色。

以下代码设置颜色:


private final void customizeNimbusLaF() {       
UIManager.put( "control" , UIConstants.GREY_LIGHT );
UIManager.put( "nimbusAlertYellow" , UIConstants.YELLOW );
UIManager.put( "nimbusBase" , UIConstants.GREY_DARK );
UIManager.put( "nimbusDisabledText" , UIConstants.GREY_DARK );
UIManager.put( "nimbusFocus" , UIConstants.BLUE_LIGHT );
UIManager.put( "nimbusGreen" , UIConstants.GREEN );
UIManager.put( "nimbusInfoBlue" , UIConstants.BLUE_MIDDLE );
UIManager.put( "nimbusRed", UIConstants.RED );
UIManager.put( "nimbusSelectionBackground",
UIConstants.BLUE_MIDDLE );

UIManager.put( "background" ,UIConstants.GREY_LIGHT );
UIManager.put( "controlDkShadow" , UIConstants.GREY_DARK );
UIManager.put( "controlShadow", UIConstants.GREY_MIDDLE );
UIManager.put( "desktop", UIConstants.BLUE_MIDDLE );
UIManager.put( "menu", UIConstants.GREY_LIGHT );
UIManager.put( "nimbusBorder", UIConstants.GREY_MIDDLE );
UIManager.put( "nimbusSelection", UIConstants.BLUE_MIDDLE );
UIManager.put( "textBackground", UIConstants.BLUE_LIGHT );
UIManager.put( "textHighlight", UIConstants.BLUE_LIGHT );
UIManager.put( "textInactiveText", UIConstants.GREY_MIDDLE );

// panel
UIManager.put( "Panel.background", UIConstants.GREY_LIGHT );
UIManager.put( "Panel.disabled", UIConstants.GREY_LIGHT );
UIManager.put( "Panel.font", UIConstants.DEFAULT_FONT );
UIManager.put( "Panel.opaque", true );

// button
UIManager.put( "Button.background", UIConstants.GREY_LIGHT );
UIManager.put( "Button.disabled", UIConstants.GREY_LIGHT );
UIManager.put( "Button.disabledText", UIConstants.BLUE_MIDDLE );
UIManager.put( "Button.font", UIConstants.DEFAULT_FONT );

// menu
UIManager.put( "Menu.background", UIConstants.GREY_LIGHT );
UIManager.put( "Menu.disabled", UIConstants.GREY_LIGHT );
UIManager.put( "Menu.disabledText", UIConstants.GREY_DARK );
UIManager.put( "Menu.font", UIConstants.MENU_FONT );
UIManager.put( "Menu.foreground", UIConstants.BLACK );
UIManager.put( "Menu[Disabled].textForeground",
UIConstants.GREY_MIDDLE );
UIManager.put( "Menu[Enabled].textForeground", UIConstants.BLACK );
UIManager.put( "MenuBar.background", UIConstants.GREY_LIGHT );
UIManager.put( "MenuBar.disabled", UIConstants.GREY_LIGHT );
UIManager.put( "MenuBar.font", UIConstants.MENU_FONT );
UIManager.put( "MenuBar:Menu[Disabled].textForeground",
UIConstants.GREY_MIDDLE );
UIManager.put( "MenuBar:Menu[Enabled].textForeground",
UIConstants.BLACK );
UIManager.put( "MenuItem.background", UIConstants.GREY_LIGHT );
UIManager.put( "MenuItem.disabled", UIConstants.GREY_LIGHT );
UIManager.put( "MenuItem.disabledText", UIConstants.GREY_MIDDLE );
UIManager.put( "MenuItem.font", UIConstants.MENU_FONT );
UIManager.put( "MenuItem.foreground", UIConstants.BLACK );
UIManager.put( "MenuItem[Disabled].textForeground",
UIConstants.GREY_MIDDLE );
UIManager.put( "MenuItem[Enabled].textForeground",
UIConstants.BLACK );

// tree
UIManager.put( "Tree.background", UIConstants.BLACK );
}
UIConstants 中常量的数据类型是 Color 类型之一的 Font取决于要设置的属性。

有人可以告诉我我的问题在哪里吗?

问候
迈克尔

最佳答案

不知道你尝试了什么,因为

  • 设置 UImanager 的所有设置在创建 Swing GUI 之前并开始AWT Thread
  • 您必须调用 SwingUtilities.updateComponentTreeUI(window)在所有情况下,Swing GUI可见,您需要在运行时更改 L&F
  • 单独的问题可能与 XxxUIResources 有关,但没有看到你的 SSCCE 就不知道了
  • 为了获得更好的帮助,请尽快发布 SSCCE演示了您关于 Nimbus L&F 的问题, UIManager 的值和 Colors保持不变
  • 关于java - Nimbus Look&Feel refresh Painter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12387364/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com