Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4776403

setRolloverEnabled(true) not working for JMenuItem

    XMLWordPrintable

Details

    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)
      ======================================================================

      Attachments

        Activity

          People

            Unassigned Unassigned
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: