JMenuItem unwanted tint

272 views Asked by At

I am creating a program that uses both a JMenuBar and a JPopupMenu with a windows LaF (look and feel).

Here is the simplified LaF code:

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    UIManager.put("MenuItem.selectionBackground", Color.BLUE);
    UIManager.put("MenuItem.selectionForeground", Color.WHITE);
    UIManager.put("MenuItem.background", Color.BLACK);
    UIManager.put("MenuItem.foreground", Color.WHITE);

MouseListener code:

@Override
public void mouseExited(MouseEvent e) {
    if (e.getSource() instanceof JMenuItem) {
        JMenuItem i = (JMenuItem) e.getSource();
        i.setBackground(UIManager.getColor("MenuItem.background"));
    }
}

@Override
public void mouseEntered(MouseEvent e) {
    if (e.getSource() instanceof JMenuItem) {
        JMenuItem i = (JMenuItem) e.getSource();
        i.setBackground(UIManager.getColor("MenuItem.selectionBackground"));
    }
}

I am trying to remove what seems to be a windows LaF artifact that tints the selected JMenuItem white. When I disable the components they no longer receive said tint.

I can't seem to find any mention of this effect online, and it also appears to show only slightly on JMenus (might be the darker color though) when their popup is active.

Edit: I believe it called "HOT" in java.beans.PropertyChangeEvent:

eg: [oldValue=NORMAL; / newValue=HOT;]

Example:

example

1st and 2nd image: show JMenu with no tint.

3rd image: this is the effect I'm talking about.

4th image: when I'm not hovering over JMenuItem

5th image: this is what it shows when I setEnabled to false, I want it to look like this without disabling it.

Does anyone know how to remove this?

0

There are 0 answers