简体   繁体   中英

Java swing application look and feel appears different in netbeans and eclipse

I am using Netbeans IDE 7.4 for developing java swing application, where in I am trying to set the look and feel to be native. While I run the application the look and feel is not that of windows (My OS is Windows 8).

I tried using eclipse for the same where in what ever look and feel I provide in code, it appears for eg: Nimbus, Window etc.

I wanted to continue developing this application in Netbeans due to its drag and drop capabilities which saves lot of time in writing GUI specific code.

Following is the code snippet which gives me windows look and feel when it is build and run from eclipse but does not give windows look and feel when build and run from Netbeans:

for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            try {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (UnsupportedLookAndFeelException e) {
                e.printStackTrace();
            }
            break;
        }
    }

The NetBeans IDE generates code, collapased with a "[+]" in the margin - so not obvious at first glance. I believe in the start of the main method, installing a Nimbus look-and-feel. Not quite sure, but look at the code.

In every case, it seems you are doing it earlier, that the NetBeans generated code, as there is a difference. Simple do a Find in the open project for setLookAndFeel .

Have your tried?

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

or

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

For other ways have a look at How to Set the Look and Feel . A lot of sample codes are mentioned there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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