javaswinguser-interfaceflatlaf

Java Swing and Flatlaf - Issue changing JFrame menu bar colour


My program should be able to change themes between dark and light mode like most applications. It will use Flatlaf to do this (i.e. UIManager.setLookAndFeel). However because the window is decorated, the menu bar won't match the theme of the application as I assume windows is overwriting it.

I set the JFrame to be undecorated which managed to change the colour of the window, but I couldn't move it around, resize it and snap the window into place. Is there a way to get it so that my menu bar matches the theme I want and maintains the windows functionality.

Currently it looks like this with full windows functionality. My application menu bar with the wrong colour:

https://i.sstatic.net/R2sRJ.png

Undecorated it looks correct but without windows functionality. My application menu bar with the correct colour

https://i.sstatic.net/C5Iqe.png


Solution

  • Never mind, found my answer.

    Realised that I was setting the java swing look and feel and then adding my own menu bar to the window which would have the default theme, thus looking out of place (i.e. like the first picture)

    Just had to set the theme after I've created the menu bar and update my JFrame's component tree