Java is another Animal II: Selecting the Look and Feel

Writing Java Swing Applications makes it comfortable to have complex and reliable GUI programming. But like always: when you have a GUI you may want to have another look and feel.

One of the most interesting Java Swing functionalities is the possibility to change the Look and Feel. Like I showed in the former tutorial the change of the look and Feel can be done line this:

Setting this Code to your Public Static Void Main before building the GUI itself selects NIMBUS look and Feel. Nimbus is a modern looking look and feel for Swing. There are also another selectable Options like you can see for example on this Oracle Page: How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With Swing > Modifying the Look and Feel).

But also Third Party Look and Feels are available. Let’s take a look on my favorite one: FlatLaf. While you can download FlatLaf at the JFormdesigner Page here: FlatLaf - Flat Look and Feel | FormDev you can install it in a really simple wise. So lets do it.

We generate at first a small GUI Project with simple UI Elements on it, like this:

It’s looking so with the Nimbus Look and Feel. Now we want to get all the FlatLaf look and Feels from the Formdev Site. First get the latest jar file of it, when writeing this tutorial it was FlatLaf 1.2. After downloading the Jar File.

When downloaded you open the Project Settings in IntelliJIdea Project and select Libraries. There you click on the small + and select Java:

The System asks you to select the Library, in this case it is the jar File we downloaded:

and press okay. The IDE asks now to which Module it shall add it. The Module is named like your Program, in this case untitled6:
Press on OK to accept it.

The IDE now added it. Press on OK to store this Settings. The IDE will add it to your list of external Libraries:

Now we can use this Library in our Programs. While FlatLaf is a nice “Animal” you can install a Look and Feel from the FlatLaf Look and Feels with a simple Install order instead of our UI Selector we used until now so first we clean our Publis Static Void Main:
and set directly to the beginning of the Method:
Pressing now the green run Arrow results in:
Changing FlatLightLaf() to FlatIntelliJLaf() brings this result:
And FlatDarculaLaf() brings this result:
To see which Themes are in the Jar you can download the Demo and start it from command Line with java -jar name_of_the_jar.jar. Have fun.


Any fix for the Close , Minimize and Maximize buttons being on the wrong side and in the wrong order?

It was not on Mac sir

Here is a Screenshot of an App @Jeannot was writing in JavaFX and running on MAC:

he showed this Screenshot in another Thread on this Site you may look on it here:

as you can see it is not a bug. It is so that I was running on Linux with a Design near to MacOS and of course it was there the other way around.

Have a nice day

As addendum: it is also possible to place the menu bar on top of the screen, you can decide by self how you want to do this.

In Java Swing and also JavaFX the Window by self is controlled by the OS, Java is not controlling that. You can do that when setting the Window on undecorated and styling the window decoration by self but I would not recommend that.

1 Like

Exactly, my screenshot is “out-of-the-box”, but you could even tweak it more, in case you have the balls, the knowledge and patients of this guy:

As @thorstenstueker mentioned, you can just say in JavaFX that you don’t want any windows decoration and you can build everything on your own. JavaFX is basically a clean empty canvas and you can draw and animate whatever you want. That’s not worth my time and I don’t have the appetite for it, but it is good knowing that I could do it.

The movie is showing another typical thing in the Java universe, most of the stuff is open source. You don’t need to start from scratch. Take Gerrit’s works an adapt it where you’ll see fit. That’s one of the very nice things of Java, little to no need to re-invent the wheel …

1 Like