Reputation: 1992
I try to use UIManager.setLookAndFeel
function to change the appearance of my java application but it makes no effect to the visual appearance of my JFrame
/buttons. I use Netbeans 7.4
and my application is 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);
}
I used
com.sun.java.swing.plaf.motif.MotifLookAndFeel
javax.swing.plaf.metal.MetalLookAndFeel
com.sun.java.swing.plaf.gtk.GTKLookAndFeel
UIManager.getSystemLookAndFeelClassName()
UIManager.getCrossPlatformLookAndFeelClassName()
but non of them changed anything of appearance of my companent. How can I make this function take effect?
Upvotes: 1
Views: 3333
Reputation: 109547
One might inspect all look-and-feels:
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);
}
Probably the look-and-feel is set a second time. For beginners finding this question: L&F only works for swing; if one uses awt Button (instead of JButton) or JavaFX, you will see no change too.
You could do:
UIManager.addPropertyChangeListener(...);
and on any change do your change afterwards.
Upvotes: 1