FlatLaf icon indicating copy to clipboard operation
FlatLaf copied to clipboard

JCheckBoxMenuItem background

Open MerlinUKRhapsody opened this issue 1 year ago • 2 comments

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: image 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 ?

MerlinUKRhapsody avatar Jun 25 '24 07:06 MerlinUKRhapsody

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/

DevCharly avatar Jun 26 '24 15:06 DevCharly

Got - thank you so much !

MerlinUKRhapsody avatar Jun 27 '24 08:06 MerlinUKRhapsody