Roland Schneider
Roland Schneider

Reputation: 3635

How to change the look and feel in NetBeans GUI Designer Preview?

When using the NetBeans GUI Builder the "Preview Design" feature shows the panel with the system look and feel (e.g. Windows). Now I want to preview my panel with a different LaF to get all the gaps and spaces right. Is there a way to tell the gui builder to display the panel with a different LaF?

Upvotes: 18

Views: 67170

Answers (6)

Menkarus
Menkarus

Reputation: 11

As of today, you need to add the following dependency to your pom.xml:

<dependency>
   <groupId>com.formdev</groupId>
   <artifactId>flatlaf</artifactId>
   <version>3.5.4</version>
</dependency>

In your main class, add the following import statement:

import com.formdev.flatlaf.FlatLightLaf;

Then, use the following code to set up the FlatLaf look-and-feel:

try {
    // Set up FlatLaf look-and-feel (light theme)
    FlatLightLaf.setup();
    // Alternatively, you can use: UIManager.setLookAndFeel(new FlatLightLaf());
} catch (Exception ex) {
    System.err.println("Failed to initialize FlatLaf");
    ex.printStackTrace();
}

Now, you're all set to go!

Upvotes: 1

loverBoy
loverBoy

Reputation: 125

change LaF using preview design will not change the look. it only going to show you how the look is but if you want to change it you have to go to source then look for this code if you did not find it click on + symbol and change the word Windows to what ever you like note:you have to change it for all the jframes to work well

try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            javax.swing.UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

Upvotes: 6

Martijn Courteaux
Martijn Courteaux

Reputation: 68847

The only thing I can find is:

Inspector > Right click on your JFrame > Preview Design

enter image description here

Upvotes: 15

geo
geo

Reputation: 527

You can change the of the preview by: Tools-Options Miscellaneous tab Windows tab Look and Feel:Preferred look and feel.

With this the look and feel of the IDE changes too.

Upvotes: 1

user1362394
user1362394

Reputation: 89

Write this in your main:

try { 
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 
} catch (Exception ex) { 
    ex.printStackTrace(); 
}

Upvotes: 8

Sam
Sam

Reputation: 3659

You can edit the look of the whole designer if you like...

In <netbeans_home>/etc/netbeans.conf, append the following to the netbeans_default_options setting:

--laf de.muntjak.tinylookandfeel.TinyLookAndFeel --cp:p path\to\tinylaf.jar"

(substituting TinyLAF for wahtever LAF you are using)

Upvotes: 5

Related Questions