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

REGRESSION: Empty JMenu w/ dynamic menu items

XMLWordPrintable

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

      ADDITIONAL OS VERSION INFORMATION :
      Windows 2000, Service Pack 4

      A DESCRIPTION OF THE PROBLEM :
      Our application has a JMenu whose contents are filled dynamically when the JMenu opens. This worked well since JDK1.3.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute test code below. Click on "File" menu. Now move the mouse right, so the "Edit" menu opens. With JDK5 and Windows LuF, the "File" menu is rendered with empty menu items.

      Remove the Windows LuF settings, and try again. Now the "Edit" menu opens with all menu items as expected.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "Edit" menu shows menu item text.
      ACTUAL -
      "Edit" menu opens blank.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.*;
      import javax.swing.event.ChangeEvent;
      import javax.swing.event.ChangeListener;

      public class JMenuTestCase {
          private JMenu editMenu;

          public JMenuTestCase() {
      // ---- SNIP ----
      // REMOVE LINES BETWEEN SNIP/SNAP TO MAKE CODE WORK ON WINDOWS:
      try {
      UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
      } catch (Exception x) {
      x.printStackTrace();
      }
      // ---- SNAP ----

      JFrame frame = new JFrame( "JMenu test case" );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

      JMenuBar mb = new JMenuBar();
      JMenu menu = mb.add( new JMenu( "File" ) );
      for (int i=0; i<5; ++i) {
      menu.add(new JMenuItem("File Item " + i));
      }
      editMenu = mb.add(new JMenu( "Edit"));
      for (int i=0; i<10; ++i) {
      editMenu.add( new JMenuItem("Edit Item " + i));
      }
      menu = mb.add(new JMenu( "Window"));
      for(int i=0; i<3; ++i) {
      menu.add( new JMenuItem("Window Item " + i));
      }
      frame.setJMenuBar(mb);

      editMenu.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
      if (!editMenu.isSelected()) {
      return;
      }
      editMenu.removeAll();
      long t = System.currentTimeMillis();
      for (int i=0; i<10; ++i) {
      editMenu.add(new JMenuItem( t + " " + i));
      }
      }
      });

      frame.setSize(300, 200);
      frame.setVisible(true);
          }


          public static void main(String[] args) {
      new JMenuTestCase();
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Directly click on "Edit" JMenu item to open it. Do not move the mouse from one JMenu to the other.

      Release Regression From : 1.4.2
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-06-15 23:02:59 GMT

            alexp Alexander Potochkin (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: