0

JSeparatorの色を変更する方法JSeparatorの答えに基づいて、垂直方向の色をNimbusのデフォルトの黒から赤に変更しようとして試みたのは次のとおりです。:

public class TestFrame extends JFrame {

    public static void main(String[] args) {

        TestFrame frame = new TestFrame();
        frame.setSize(200, 200);
        frame.setLayout(new GridBagLayout());

        for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                try {
                    UIManager.setLookAndFeel(info.getClassName());
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(TestFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(TestFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(TestFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(TestFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;
            }
        }
        UIManager.put("Separator.background", Color.red);
        UIManager.put("Separator.foreground", Color.red);

        JSeparator separator = new JSeparator(JSeparator.VERTICAL);
        separator.setPreferredSize(new Dimension(2, 100));
        separator.setForeground(Color.red);
        separator.setBackground(Color.red);

        frame.add(separator, new GridBagConstraints());
        frame.setVisible(true);

    }

}

それでも、垂直セパレーターは黒のままです。私は何をすべきですか?

注:L&FをNimbusに設定せずに試してみたところ、Nimbusが問題であることがわかりました。これはうまくいきました。また、Separator[Enabled].backgroundPainterプロパティの設定が影響しているように見えますJSeperatorが、意図した方法ではないようです(背景色と区切り線の色を変更しただけです)

4

2 に答える 2

1

nimbusBlueGreyNimbus が他の色を派生させるために使用する色を変更することで、これを解決しました。セパレータを不透明に設定すると、背景色の変更に役立ちますがJSeperator's、前景と背景の 2 つの色があるため、不透明に設定して背景色を変更すると、問題の半分が修正されます。またはプロパティnimbusBlueGreyでオーバーライドできないように見える前景色を処理しているようです。setForegroundcolor()Separator.foreground

問題は、変更nimbusBlueGreyが他の多くのコンポーネントの色に影響を与えることです。JSeperator だけに色の変更を含める方法がわかりません。

于 2016-08-19T20:57:41.130 に答える