JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.42k stars 272 forks source link

Submenu styling separate from top level menus #587

Closed rkeen-siemens closed 2 years ago

rkeen-siemens commented 2 years ago

When customizing menu colors, you can change the selection color for a menu via Menu.selectionBackground and for a menu item via MenuItem.selectionBackground. However, it appears that Menu.selectionBackground applies to both the top level menu (e.g. JMenu in the menu bar) and any submenus (e.g. JMenu > JMenu in the drop down menu) as shown below.

Menu Colors

Is it possible to have a different color for top level menus and submenus? Or is there a way to have submenus use the menu item colors?

DevCharly commented 2 years ago

Yes, it is possible in latest 2.5-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

There are two new UI properties MenuBar.selectionBackground and MenuBar.selectionForeground that are used for top level menus (JMenu components in JMenuBar). See also https://www.formdev.com/flatlaf/components/menubar/

Usage (for all menu bars):

UIManager.put( "MenuBar.selectionBackground", Color.green );
UIManager.put( "MenuBar.selectionForeground", Color.red );

Styling is also supported (for single menu bar):

menuBar.putClientProperty( "FlatLaf.style", "selectionBackground: #0f0; selectionForeground: #f00" );