Here is what I've tried in my attempt to change a vertical JSeparator
's color from Nimbus default black to red based on the answer in How to change the color of a JSeparator?:
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);
}
}
Yet the vertical separator remains black. What should I be doing?
Note: I know Nimbus is the issue, because I tried without setting the L&F to Nimbus and this worked fine. Also to note that setting the Separator[Enabled].backgroundPainter
property seems to have affected the JSeperator
but not in the way I intended (just changed the background color vs the separating line color)