我注意到TitledBorder
具有原生外观的 Windows 上的 Java 8(及更早版本)和 Java 9(及更高版本)的外观有所不同。从 Java 9 开始,边框变暗并且没有圆角。尤其是嵌套TitledBorder
的,这看起来令人不安。有没有办法使用 Java 9 并像 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);
});
}
}