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
が、意図した方法ではないようです(背景色と区切り線の色を変更しただけです)