我尝试使用UIManager.setLookAndFeel函数来更改我的java应用程序的外观,但它对JFrame/buttons的可视化外观没有任何影响。我使用Netbeans 7.4,我的应用程序是Java Swing Desktop Application。
/**
* Main method launching the application.
*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} catch (Exception e) {
System.out.println(e.getMessage());
}
System.out.println("init");
launch(JavaMysqlTestApp.class, args);
}我用过
com.sun.java.swing.plaf.motif.MotifLookAndFeeljavax.swing.plaf.metal.MetalLookAndFeelcom.sun.java.swing.plaf.gtk.GTKLookAndFeelUIManager.getSystemLookAndFeelClassName()UIManager.getCrossPlatformLookAndFeelClassName()但它们都没有改变我的同伴的外貌。我怎样才能使这个功能生效?
发布于 2014-03-13 07:25:22
人们可能会检查所有的外观和感觉:
try {
LookAndFeel laf = UIManager.getLookAndFeel();
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
...
if (laf.getName().equals(info.getName())) {
...;
}
}
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException ex) {
Logger.getLogger(NewJFrame1.class.getName()).log(Level.SEVERE, null, ex);
}可能外观和感觉是设置的第二次。对于初学者来说,发现这个问题: L&F只适用于swing;如果您使用awt Button (而不是JButton)或JavaFX,您也不会看到任何变化。
你可以这样做:
UIManager.addPropertyChangeListener(...);如果有任何变化,以后再做你的改变。
https://stackoverflow.com/questions/22371606
复制相似问题