views:

577

answers:

3

I'm a Java/Netbeans newbie learning how to make a GUI.

I was following this tutorial, and I noticed that the "finished" product (first picture in that link) doesn't look like the GUI built through the steps.

Why is that? I mean, when I click on the preview button, the GUI looks native (nice) as well. It's just when it's deployed that it looks all...mmm...bad. lol.

Is there a way to make the finished GUI looks native? Is it Netbeans settings or Java settings?

Note: I'm developing this on Windows.

+1  A: 

This is referred to as the "look and feel". You can use various look and feel either when launching your app or programaticaly. See this Sun tutorial for more info.

JRL
+4  A: 

Use the following code to force swing to select the "system" look and feel:

String laf = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(laf);
Ramon
that was easy. thanks!
ShaChris23
+1  A: 

The default "Look and Feel" is metal-like, which is good and nice for cross-platform applications.

JDK has 4 built-in "look and feel" ('til now), which are:

  • com.sun.java.swing.plaf.gtk.GTKLookAndFeel
  • javax.swing.plaf.metal.MetalLookAndFeel
  • com.sun.java.swing.plaf.windows.WindowsLookAndFeel
  • com.sun.java.swing.plaf.motif.MotifLookAndFeel

you can try any of these "look and feel"s in 1 line, example code:

UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

NOTE: invoke/call this method of changing the "look and feel" before any GUI implementation, or it may throw some exception

evilReiko
ooh..thanks! I will definitely give it a try.
ShaChris23