JDK-4776403 : setRolloverEnabled(true) not working for JMenuItem
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.1,1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-11-08
  • Updated: 2019-12-17
  • Resolved: 2019-12-17
Description
Name: jk109818			Date: 11/08/2002


FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
The rollover effect is not evidenced when it is specified
for instances of JMenuItem, JCheckBoxMenuItem, or
JRadioButtonMenuItem in Java 1.4.1 running on Windows 2000.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Create an instance of a JMenuItem that specified a
rollover icon through the JMenuItem.setRolloverIcon(Icon)
method and which calls JMenuItem.setRolloverEnabled
(boolean).
2.Set the instance in a GUI application.
3.The JMenuItem's icon doesn't switch to the rollover one
when it is moused over.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I expect the rollover effect to be evidenced the way it is
with JButtons where mousing over the JMenuItem changes the
icon to the rollover icon when it is set.  Instead, no
change is evidenced.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.io.*;

import javax.swing.*;

public class RolloverTest extends JFrame {

    public RolloverTest() {
        super("Rollover Test");
        
        installMenuBar();
        
        Dimension screenSize = getToolkit().getScreenSize();
        setSize(screenSize.width / 2, screenSize.height / 2);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }
    
    private void installMenuBar() {
        JMenuBar menubar = new JMenuBar();
        menubar.add(createSquaresMenu());
        setJMenuBar(menubar);
    }
    
    private JMenu createSquaresMenu() {
        JMenu squaresMenu = new JMenu("Menu");
        squaresMenu.add(createSquareIconMenuItem());
        squaresMenu.add(createSquareIconMenuItem());
        squaresMenu.add(createSquareIconMenuItem());
        squaresMenu.addSeparator();
        squaresMenu.add(createSquareIconMenuItem());
        return squaresMenu;
    }
    
    private JMenuItem createSquareIconMenuItem() {
        JMenuItem squareMenuItem =
            new JMenuItem("Square", new SquareIcon(false));
        squareMenuItem.setRolloverIcon(new SquareIcon(true));
        squareMenuItem.setRolloverEnabled(true);
        return squareMenuItem;
    }
    
    private static class SquareIcon implements Icon, Serializable {
    
        private boolean rollover;
        
        public SquareIcon(boolean rollover) {
            this.rollover = rollover;
        }
        
        public int getIconWidth() {
            return 16;
        }
        
        public int getIconHeight() {
            return 16;
        }
        
        public void paintIcon(Component c, Graphics g, int x, int y) {
            g.setColor(rollover ? Color.white : Color.black);
            g.fillRect(x, y, 16, 16);
        }
    }
    
    public static void main(String[] args) {
        new RolloverTest();
    }
}
---------- END SOURCE ----------

CUSTOMER WORKAROUND :
A MouseListener can be used to simulate rollover behaviour.
(Review ID: 165212) 
======================================================================

Comments
EVALUATION The Peabody fix looks interesting. We could integrate it into Mustang.
03-07-2006

EVALUATION Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=13513
08-06-2006

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
25-09-2004

EVALUATION Will be fixed in Tiger
25-09-2004