Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java, Netbeans: How come the GUI looks different?

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.

like image 796
sivabudh Avatar asked Dec 13 '22 01:12

sivabudh


2 Answers

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

String laf = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(laf);
like image 180
Ramon Avatar answered Dec 28 '22 10:12

Ramon


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

like image 35
evilReiko Avatar answered Dec 28 '22 10:12

evilReiko