I noticed a difference in the appearance of a TitledBorder
between Java 8 (and earlier) and Java 9 (and later) on Windows with native look-and-feel. Starting with Java 9, the border is darker and doesn't have round corners. Especially with nested TitledBorder
, this looks disturbing. Is there a way to use Java 9 and have the border painted like in Java 8?
MWE:
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
public class TitledBorderWithJava9 {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
//...
}
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(150, 100);
JPanel panel = new JPanel();
frame.add(panel);
TitledBorder border = BorderFactory.createTitledBorder("Title");
panel.setBorder(border);
frame.setVisible(true);
});
}
}