1

Swing アプリケーションで 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

誰かが私の問題がどこにあるのか教えてもらえますか?

マイケルに挨拶

4

3 に答える 3

4

何を試したのかわかりません。

  • UImanagerを作成しSwing GUIて開始する前に、すべての設定を設定してくださいAWT Thread

  • SwingUtilities.updateComponentTreeUI(window)表示されているすべての場合に電話をかけるSwing GUI必要があり、実行時にL&Fを変更する必要があります

  • 分離された問題はにある可能性がありますが、 SSCCEXxxUIResourcesを見ないとわかりません

  • より良いヘルプのために、SSCCEがあなたの問題を示しNimbus L&F、価値がUIManagerあり、Colors変わらないことをより早く投稿する

于 2012-09-12T12:16:38.023 に答える