5

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?

Daedric
  • 502
  • 4
  • 23
  • I created a [mcve] with the above constraints (Note that you don't include `UIManager.put("Menu.___")` in your post) and couldn't reproduce your problem. – MasterBlaster Dec 30 '16 at 18:02
  • I think you're missing the point, its not about the code its a Windows 7 Swing look and feel effect that mimics the effect windows 7 shows on its GUI and I want to disable it, I can '@Override' the 'paintComponent' method but I don't know how to redraw the text, arrow and icon in the exact same fashion. I added the colors to distinguish the effect and supplied the simplified code to show that I'm not adding the effect. – Daedric Dec 31 '16 at 01:30
  • 2
    1) Create a [mcve] to remove any doubt of incorrect reproduction. 2) Is it only on Win 7, or on 8 and 10 too? – user1803551 Dec 31 '16 at 04:28
  • add this line UIManager.put("Menu.opaque", false); to LaF code – Cassian Jan 03 '17 at 10:19
  • You don't need the code in MouseListener. By setting the UIManager properties, you've already done those. Remove the code in MouseListener. – Doga Oruc Sep 08 '20 at 09:14

0 Answers0