Search code examples
javaswingflatlaf

How can I make the tabs in the menu bar with rounded corners and margins in Java/Swing using FlatLaf Theme Editor?


I'm creating a Java application with Swing as the GUI. I'm using FlatLaf themes FlatLightLaf.

On the JMenuBar I want to create something like this:

VSCode Title Bar (https://i.sstatic.net/jo0tolFd.png)

But I end up with something like this:

Java Theme Editor Preview (https://i.sstatic.net/fzq7fFp6.png)

The problem is with the margins. I want to add space between the hover background and the actual background. To be clear I want the hover background to have a margin.

How can I achieve this?

I tried to use FlatLaf Theme Editor and this is how my FlatLaf.properties file looks like:

MenuBar.itemMargins = 10, 10, 10, 10
MenuBar.selectionArc = 20

But it didn't work. It just made the tab sizes bigger instead of adding space around it.


Solution

  • Okay i figured it out. I should have used MenuBar.selectionInsets along with MenuBar.itemMargins. So the FlatLaf.properties file now looks like this:

    MenuBar.itemMargins = 10, 15, 10, 15
    MenuBar.selectionArc = 20
    MenuBar.selectionInsets = 5, 5, 5, 5
    

    And now the UI looks like this [1]