Match theme color in MenuBarCustomizer?

Post here questions and problems related to oXygen frameworks/document types.
queshaw
Posts: 38
Joined: Wed Aug 08, 2007 5:56 am

Match theme color in MenuBarCustomizer?

Post by queshaw » Fri Nov 22, 2019 3:21 am

Hi,

I know very little Swing. How can I match the theme color when adding a menu and menu item? My latest attempt:

Code: Select all

                    Color bg = (Color) UIManager.get("MenuBar.background");
                    Color fg = (Color) UIManager.get("MenuBar.foreground");
                    UIManager.put("MenuItem.background", bg);
                    UIManager.put("MenuItem.foreground", fg);
                    UIManager.put("Menu.background", bg);
                    UIManager.put("Menu.foreground", fg);
                    JMenu menu = new JMenu("Some");
                    JMenuItem item = new JMenuItem(createSyncAction(...));
                    item.setSelected(false);
                    item.setMnemonic(KeyEvent.VK_ALT | KeyEvent.VK_S);
                    item.setBackground(bg);
                    item.setForeground(fg);
                    item.setOpaque(true);
                    menu.add(item);
                    menu.setSelected(false);
                    menu.setMnemonic(KeyEvent.VK_ALT | KeyEvent.VK_A);
                    menu.setBackground(bg);
                    menu.setForeground(fg);
                    menu.setOpaque(true);
                    menuBar.add(menu, menuBar.getMenuCount() - 1);
I also tried menuBar.getBackground()/getForeground() instead of UIManager.get.
Kendall

Radu
Posts: 6578
Joined: Fri Jul 09, 2004 5:18 pm

Re: Match theme color in MenuBarCustomizer?

Post by Radu » Fri Nov 22, 2019 12:50 pm

Hi Kendall,

Instead of JMenu you should create an Oxygen specific ro.sync.exml.workspace.api.standalone.ui.Menu.
After this avoid creating the JMenuItem, use the method javax.swing.JMenu.add(Action) to directly add the action to the menu.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

queshaw
Posts: 38
Joined: Wed Aug 08, 2007 5:56 am

Re: Match theme color in MenuBarCustomizer?

Post by queshaw » Fri Nov 22, 2019 8:00 pm

Thank you!

Post Reply