How to set look and feel on Java Swing applications


Use the method setLookAndFeel like the following to change Java Swing applications’ appearance

try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} catch (Exception ex) {
//Just print stacktrace here since it's an example.
ex.printStackTrace();
}

And if you get an exception like the following one while trying to integrate SyntheticaStandardLookAndFeel for your application;

java.text.ParseException: Error parsing: org.xml.sax.SAXException: bind: unknown type REGİON null
    at javax.swing.plaf.synth.SynthParser.parse(SynthParser.java:230)
    at javax.swing.plaf.synth.SynthLookAndFeel.load(SynthLookAndFeel.java:589)
    at de.javasoft.plaf.synthetica.SyntheticaLookAndFeel.loadXMLConfig(SyntheticaLookAndFeel.java:401)
    at de.javasoft.plaf.synthetica.SyntheticaLookAndFeel.<init>(SyntheticaLookAndFeel.java:339)
    at de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel.<init>(SyntheticaStandardLookAndFeel.java:30)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at javax.swing.UIManager.setLookAndFeel(UIManager.java:558)
    at examples.WelcomeForm.main(WelcomeForm.java:246)

You should change your current locale to English before setting Look and Feel like the code below;

Locale.setDefault(Locale.ENGLISH);
try {
UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel");
} catch (Exception ex) {
//Just print stacktrace here since it's an example.
ex.printStackTrace();
}

example Look and Feel class names;

javax.swing.plaf.metal.MetalLookAndFeel
com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s