簡體   English   中英

Nimbus Look&Feel 刷新 Painter

[英]Nimbus Look&Feel refresh Painter

我在我的 Swing 應用程序中使用了 Nimbus 的外觀和感覺。

我設置了外觀的UIDefaults的主要和次要屬性。 顏色是對的。 現在我遇到了問題,組件的畫家使用了在更新顏色主題之前定義的顏色。

有沒有辦法更新所有組件的畫家以使用新顏色,或者我是否需要為每個屬性實現自定義畫家?

UIDefaults設置屬性后,我已經調用了SwingUtilities.updateComponentTreeUI(window)

編輯:

以下代碼設置整個應用程序的 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中常量的數據類型是Font Color類型,具體取決於要設置的屬性。

有人能告訴我我的問題出在哪里嗎?

問候邁克爾

不知道你嘗試了什么,因為

  • 在創建Swing GUI並啟動AWT Thread之前設置UImanager所有設置

  • 你必須在Swing GUI可見的所有情況下調用SwingUtilities.updateComponentTreeUI(window)並且你需要在運行時更改L&F

  • 分離的問題可能是XxxUIResources ,但沒有看到你的SSCCE也不知道

  • 為了更好的幫助,在SSCCE上發布了關於Nimbus L&FUIManagerColors價值保持不變

將這些位置更改為代碼行

       UIManager.setLookAndFeel(info.getClassName());
       customizeNimbusLaF();

       customizeNimbusLaF();
       UIManager.setLookAndFeel(info.getClassName());

我想為這里提出的這種方法添加一個替代方法。

尤其是下期描述的UIManager相關的所有問題,都由material-ui-swing庫以Material Theming System的概念解決。

材料主題系統給予設置你的顏色和風格決定像的可能性/無邊框,帶圓角或不被記錄的單一類的邊界在這里包下mdlaf.themes

使用示例可以是以下一個

  try {
      JDialog.setDefaultLookAndFeelDecorated(true);
      JFrame.setDefaultLookAndFeelDecorated(false);
      MaterialTheme theme = new MaterialLiteTheme();
      // here your custom config theme.setXXX();
      MaterialLookAndFeel material = new MaterialLookAndFeel(theme);
      UIManager.setLookAndFeel(material);
  } catch (UnsupportedLookAndFeelException e) {
      e.printStackTrace();
  }

您也可以保留主題,進行自定義更改,並在閱讀時調用SwingUtilities.updateComponentTreeUI(window)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM