How do I force/get to use GTKLookAndFeel in Java on KDE?

爱⌒轻易说出口 提交于 2019-12-05 13:00:30

You can set the look and feel from the command line:

java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel MyApp

Also, SwingSet2.jnlp provides a sample demo of all the different things that can be changed. The source and other info can be found here: link text

Quoting the documentation:

  1. If the system property swing.defaultlaf is non-null, use its value as the default look and feel class name.

  2. If the Properties file swing.properties exists and contains the key swing.defaultlaf, use its value as the default look and feel class name. The location that is checked for swing.properties may vary depending upon the implementation of the Java platform. In Sun's implementation the location is ${java.home}/lib/swing.properties

Refer to the release notes of the implementation being used for further details.

But I'm 99% sure that your problem is this one (quoting the docs again):

Once the look and feel has been changed it is imperative to invoke updateUI on all JComponents. The method SwingUtilities.updateComponentTreeUI(java.awt.Component) makes it easy to apply updateUI to a containment hierarchy. Refer to it for details. The exact behavior of not invoking updateUI after changing the look and feel is unspecified. It is very possible to receive unexpected exceptions, painting problems, or worse.

If you don't want to invoke updateUI on all JComponents, be sure to invoke UIManager.setLookAndFeel before every other swing code.

maybe this works:

try {
// sure look and feel
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
// not-so-sure look and feel
System.setProperty("os.name", "Windows");
System.setProperty("os.version", "5.1");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} 
catch (Exception ex) {
ex.printStackTrace();
}

The GTK Laf is, IMHO, broken period. It does not honor some random settings. I believe it is not supposed to honor any setBackground(), setForeground(), or setFont() on most components.

If you are using java >1.4.2 I suggest using MetalLookAndFeel [should be UIManager.getCrossPlatformLookAndFeelClassName()]. If you are using >1.6.0_u10 you can try NautilusLookAndFeel. I personally find Metal nicer looking.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!