How do I change the Look and Feel of an app?

Asked

Viewed 1,244 times

1

Can anyone explain to me how I change the layout of my application windows?

I was building the app and testing by the method main normally, but since it took me a long time to wait to connect to the server and still have to log in every time I wanted to test a function, I created a method main test, and when I did this I had a surprise: the layout was totally different... I don’t want to tidy up, since it’s just start by the main that gets normal, I just want to know if it has how to choose between other models.

The difference is in the images below:

This is the original

And that’s how it turned out:

1 answer

3


The original format uses the look and Feel Nimbus, the format that was left after is the Java standard. You can programmatically select the look and Feel of your application as follows:

try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
        UIManager.setLookAndFeel(info.getClassName());
        break;
    }
}
} catch (Exception e) {
   // If Nimbus is not available, you can set the GUI to another look and feel.
}

The loop iterates through all supported look and Feels and when you find Ninbus selects for your application. I hope I’ve helped ^^

  • Remembering that this form will only work if it is done before the EDT is invoked (that is, before the application opens). If you do it later, JVM will choose LAF metal, because it is cross Plataform. To change at runtime, this is how I show in this answer

  • Type, if it is the main method responsible for starting the frame, doing this loop works.

  • That’s what I said, only in other words :)

  • 1

    Yes, of course. It’s because the term EDT is more technical, I just wanted to make the comment :P more accessible

  • Thank you Giuliana, it worked perfectly

Browser other questions tagged

You are not signed in. Login or sign up in order to post.