这里的色彩是我在我试图改变从雨云默认的黑色垂直JSeparator
的颜色为红色已经试过基础上,答案How to change the color of a JSeparator?:如何改变一个JSeparator对象的使用Nimbus的L&F
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);
}
}
然而,垂直分隔符仍然是黑色的。我该怎么做?
注意:我知道Nimbus是问题所在,因为我尝试没有将L & F设置为Nimbus,并且此工作正常。另外要注意的是设置Separator[Enabled].backgroundPainter
属性似乎已经影响到了JSeperator
但不是我希望的方式(只是改变了背景色VS分隔线颜色)
的可能的复制[如何改变一个JSeparator对象的颜色?(http://stackoverflow.com/questions/13083876/how-to-改变颜色的jseparator) –
它不是重复的@JonnyHenly,因为答案只适用于金属L&F不适用于Nimbus –
@SammyGuergachi该帖子不适用于用户界面,而是直接与组件直接相关。它应该工作,不管已安装的外观和感觉。 – Mordechai