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

JMenu popup can remain on screen after becoming unobscured

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0, 1.2.2, 1.3.0
    • client-libs
    • x86
    • solaris_7, windows_95, windows_98, windows_nt



      Name: rlT66838 Date: 08/25/99


      I spent several hours tracking this one down, so I hope this
      bug report proves useful. For the testcase provided, a new window
      is opened via a JMenu item where the new window obscures the
      original window(with the menu still posted). When the new window
      is dragged out of the way the posted menu is still drawn on top
      of the original window(instead of being removed).

      Here's the code to reproduce it:

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class jdk13bug extends JFrame {

          public jdk13bug () {
              setTitle("JMenu Repaint Bug");
              addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
              });

              JMenuBar mbar = new JMenuBar();
              setJMenuBar(mbar);
              JMenu file = new JMenu("File");
              JMenuItem mi = new JMenuItem("New Window");
              mi.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      new jdk13bug();
                  }});
              file.add(mi);
              mbar.add(file);
              pack();
              setSize(400,400);
              setVisible(true);
          }

          public static void main(String[] args) {
              new jdk13bug();
          }
      }
      (Review ID: 94331)
      ======================================================================

      Name: krT82822 Date: 09/01/99


      1)

      When a JMenu creates a JFrame that overlaps the JMenu, the JMenu is not cleared correctly.

      In other words, normally after the mouse is released on a menu choice, the menu disappears and the menu command executes. And this still happens in 1.3 -- except when the menu is creating a new window that appears above where the menu used to be. It does not redraw the frame with the menu in it, so after you close the new window, you still see the menu open.

      2) Souce code is simple. In the action listener, just do a:
      JFrame foo = new JFrame("bar");
      ...(add elements to Frame)
      foo.pack();
      foo.show();

      And when foo gets closed, you will still see the menu open in the window behind it. Selecting and unselecting the menu again will clear this visual error.

      3) No error messages occur

      4) No trace information needed

      5) Just using the 1.3 plugin

      6) NA
      (Review ID: 94756)
      ======================================================================

      Name: krT82822 Date: 09/17/99


      This problem is easy to reproduce. Whenever a menu item
      generates a new window getting focus, the menu stays down.
        User must click on the menu again to pull it back up.

      This is coupled with painting problems.
      (Review ID: 95402)
      ======================================================================

      Name: skT88420 Date: 09/23/99


      import javax.swing.*;
      import java.awt.event.*;
      import java.awt.*;

      /**
       * This program demonstrates a Swing bug.
       * Under "Menu", select "Display".
       * A modal dialog box will pop up. When the dialog box
       * is put away, the menu has not been correctly closed.
       *
       * This problem occurs on Windows NT under JDK 1.3beta.
       *
       * (I reported this problem previously from JDK 1.3 docs, but
       * there was no way to specify the OS other than "Generic".
       * Java tech support claimed
       * it could not reproduce the problem when Solaris was
       * arbitrarily chosen to run the test case. If you run
      * it under Window NT, you should be able to reproduce
       * the problem.)
       */
      class T {
          public static void main(String args[]){
              final JFrame f = new JFrame();
              JMenu menu = new JMenu("Menu");
              JMenuItem item = new JMenuItem("Display");
              final JDialog dialog = new JDialog(f);
              Container pane = dialog.getContentPane();
              pane.setLayout(new BorderLayout());
              JButton close = new JButton("Close");
              pane.add(close,BorderLayout.CENTER);
              dialog.setSize(500,500);
              close.addActionListener(new ActionListener(){
                  public void actionPerformed(ActionEvent event){
                      dialog.dispose();
                      }
                  });
              item.addActionListener(new ActionListener(){
                  public void actionPerformed(ActionEvent event){
                      dialog.show();
                      }
                  });
              menu.add(item);
              JMenuBar bar = new JMenuBar();
              bar.add(menu);
              f.setJMenuBar(bar);
              f.addWindowListener(new WindowAdapter(){
                  public void windowClosing(WindowEvent event){
                      System.exit(0);
                      }
                  });
              f.setSize(500,500);
              f.show();
              }
          }
      (Review ID: 95671)
      ======================================================================

      ============ stevef, 3/9/2000 ==============

      We see this bug all the time in the deploytool GUI running on NT.
      I have tried to reproduce the problem on Solaris without success.
      Important: the bug is not seen in all cases where a resulting dialog
      obscures the JMenu that originated it. The bug is seen when the width
      of the resulting dialog is near or overlaps the border of the dialog.
      In the test case I used, if the dialog width was less than this the bug
      is not seen. So this may have to do with a race condition related
      to repaint of the JFrame border.

      I was able to work around this problem by forcing a repaint of the
      underlying graphics...this is an ugly fix but without a workaround
      the application looks pretty bad. This is because many of the deploytool
      GUI dialogs are very large wizards and hence often result in cases where
      this bug is reproduced.

      My sample code is shown below. You will need to twiddle with the window
      size after bringing up the application to reproduce the bug according to
      the positions described above. You can ignore the weird GEN comments...
      I used the Netbeans tool to write this.

       /*
       * Reproduce.java
       *
       * Created on March 8, 2000, 12:25 PM
       */
       
      package sbug;

      import javax.swing.JOptionPane;

      /**
       *
       * @author stevef
       * @version
       */
      public class Reproduce extends javax.swing.JFrame {

        /** Creates new form Reproduce */
        public Reproduce() {
          initComponents ();
          pack ();
        }

        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the FormEditor.
         */
        private void initComponents () {//GEN-BEGIN:initComponents
          aMenuBar = new javax.swing.JMenuBar ();
          aMenu = new javax.swing.JMenu ();
          aMenuItem = new javax.swing.JMenuItem ();

            aMenu.setText ("Menu");
            aMenu.setLabel ("File");
        
              aMenuItem.setText ("Bug...");
              aMenuItem.addActionListener (new java.awt.event.ActionListener () {
                public void actionPerformed (java.awt.event.ActionEvent evt) {
                  aMenuItemActionPerformed (evt);
                }
              }
              );
          
              aMenu.add (aMenuItem);
            aMenuBar.add (aMenu);
          addWindowListener (new java.awt.event.WindowAdapter () {
            public void windowClosing (java.awt.event.WindowEvent evt) {
              exitForm (evt);
            }
          }
          );

          setJMenuBar (aMenuBar);

        }//GEN-END:initComponents

        private void aMenuItemActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aMenuItemActionPerformed
         JOptionPane.showMessageDialog(this, "Show me the bug");
         // workaround is here -> this.repaint();
        }//GEN-LAST:event_aMenuItemActionPerformed

        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
          System.exit (0);
        }//GEN-LAST:event_exitForm

        /**
        * @param args the command line arguments
        */
        public static void main (String args[]) {
          new Reproduce ().show ();
        }


        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JMenuBar aMenuBar;
        private javax.swing.JMenu aMenu;
        private javax.swing.JMenuItem aMenuItem;
        // End of variables declaration//GEN-END:variables

      }

      Name: rlT66838 Date: 04/26/2000


      C:\jdk1.3RC3\demo\jfc\SwingSet2>java -version
      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)

      Run demo SwingSet2.
      Change the look and feel to Windows.
      Click on the menu Look & Feel, while the drop down list is visible, click on the
      title bar, the menu does not hide.

      In bug 4264725, it said it is closed and fixed for J2EE. I don't know why the fix
      didn't apply to J2SE.
      (Review ID: 104116)
      ======================================================================

      Name: ks88420 Date: 08/25/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      The problem is that during mouse over of several JMenu's in a menu bar, some
      menu items in the menu bar do do not refresh properly (there are remnants of
      icons from other menu items in the wrong menu item, and sometimes the menu item
      icons are partially showing or grayed out.)
      The platform is Java 1.3 running on Win98 (rev. 1) on an IBM Thinkpad laptop.
      Your response is urgently requested... we are getting close to a product
      release, and this would be a MAJOR, HIGHLY VISIBLE defect in our software.
      (Review ID: 108909)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: