开发者

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 wel开发者_开发百科l. 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.


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

String laf = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(laf);


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜