JCheckBoxMenuItem background
I have a properties file that works perfectly except for one thing - I cannot get the background of a JCheckBoxMenuItem to change. Hover background works but I cant find the property for the 'normal' background - for example:
Here are the properties I've set:
MenuBar.foreground = @Forgeround MenuBar.hoverBackground = @DEEP_TECH_RED MenuBar.selectionForeground = @WHITE MenuBar.selectionBackground = @TECH_RED MenuItem.background = @SLATE CheckBoxMenuItem.background = @SLATE MenuItem.selectionBackground = @SLATE CheckBoxMenuItem.selectionBackground = @SLATE MenuItem.checkBackground = @SLATE MenuItem.underlineSelectionBackground = @SLATE MenuItem.underlineSelectionColor = @SLATE MenuItem.underlineSelectionCheckBackground = @SLATE CheckBoxMenuItem.foreground = @SLATE CheckBoxMenuItem.selectionForeground = @Forgeround MenuItem.checkForeground = @DEEP_TECH_RED
This is the menu item:
public class AlwaysOnTopMenuItem extends JCheckBoxMenuItem { /** * */ private static final long serialVersionUID = 1L; JFrame theForm; JMenu theMenu;
public AlwaysOnTopMenuItem(JFrame frm, JMenu mnu) {
super("Always on Top");
theForm = frm;
theMenu = mnu;
init();
}
private void init() {
theForm.setAlwaysOnTop(true);
this.setSelected(true);
theMenu.add(this);
this.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED)
theForm.setAlwaysOnTop(false);
else
theForm.setAlwaysOnTop(true);
}
});
}
}
What have I missed ?
Menu items are non-opaque by default. So they do not have a background (in default state).
You probably want to change the popup menu background: https://www.formdev.com/flatlaf/components/popupmenu/
Got - thank you so much !