简体   繁体   English

Java Swing GUI-问题

[英]Java Swing GUI - Problem

I have created a GUI in Java using swings with the help of Netbeans IDE. 我已经在Netbeans IDE的帮助下使用Swing创建了Java GUI。

Now the problem is when I click on "Preview Design", the look and feel of the GUI is that of my OS ie Windows XP but when I click on "Run" button to run the application, then the look and feel of the GUI is metalic. 现在的问题是,当我单击“预览设计”时,GUI的外观是我的操作系统(即Windows XP)的外观,但是当我单击“运行”按钮以运行应用程序时,则是GUI的外观是金属的。

How can I set the tone of the GUI. 如何设置GUI的基调。 (It would be more better if the answer is wrt Netbeans IDE) (如果答案是wrt Netbeans IDE,那就更好了)

You want the UIManager class. 您需要UIManager类。

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Will change the Look & Feel to whatever the default on the system is. 会将外观更改为系统上的默认值。 You have to call it before you construct any UI objects, void main(String[] args) is a good place. 在构造任何UI对象之前,必须先调用它, void main(String[] args)是一个好地方。

In your main method, explicitly tell Swing which L&F to use, a la 在您的主要方法中,明确告诉Swing使用哪个L&F

// Metal! Woo!
try {
    UIManager.setLookAndFeel(
        UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) { }

or 要么

// Fit in. Be boring.
try {
    UIManager.setLookAndFeel(
        UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) { }

etc. 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM