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

Swing Menu doesn't unpost when focus change to anther window

XMLWordPrintable

    • tiger
    • x86
    • generic, windows_98, windows_nt, windows_2000



      Name: clC74495 Date: 03/08/99


      In either jdk1.1x and jdk1.2x, and running Swing1.0x or
      Swing1.1x, menus don't unpost if you change the native window
      focus through mouse click.

      1. Run SwingSet demo comes with Swing install
      2. Post a menu (i.e. click on File to post file menu)
      3. Click on other application window in your desktop

      You will see file menu on SwingSet still posts.
      (Review ID: 55150)
      ======================================================================

      Name: krT82822 Date: 03/18/2000


      (verified as still being present in kestrel-rc2 -- i.e., 1.3.0rc2-W on Solaris)

      2 issues:

      1) If you activate a JMenuBar, then click on a different JFrame, the JMenuBar
      in the previous JFrame still has focus, as does the new JFrame. Seems like
      focus in two locations at the same time.

      2) Using a similiar process described above, you can get into a state where
      the JMenuBar will not deactivate.

      Steps to repro
      The proper behavior
      Click in the content pane of MenuFrame 1
      Click on "File". The menu should drop down
      Again, click in the content pane of MenuFrame 1
      Notice how the JMenu no longer has focus. (it disappears)

      The problem (Pay attention to which MenuFrame # you are clicking in)
      Click in the content pane of MenuFrame 1
      Click on "File" on MenuPane 1. The menu should drop down
      Click in the content pane of MenuFrame 2
      Notice how focus is now in two places. (Seems incorrect)
      Click on "File" in MenuFrame 2
      Click in the content pane of MenuFrame 2
      Notice how the JMenu WILL NOT dissappear. (The big problem)



      Code (2 classes - MenuDemo and MenuFrame)

      import MenuFrame;
      import javax.swing.*;
      public class MenuDemo
      {
      public MenuDemo()
      {
      MenuFrame menuFrame1 = new MenuFrame();
      menuFrame1.setTitle("MenuFrame 1");
      menuFrame1.setLocation(new java.awt.Point(100, 100));
      menuFrame1.setVisible(true);

      MenuFrame menuFrame2 = new MenuFrame();
      menuFrame2.setTitle("MenuFrame 2");
      menuFrame2.setLocation(new java.awt.Point(451, 100));
      menuFrame2.setVisible(true);
      }

      static public void main(String[] args)
      {
      try
      {
      UIManager.setLookAndFeel
      (UIManager.getSystemLookAndFeelClassName());
      }
      catch ( Exception e)
      {

      }
      new MenuDemo();
      }
      }




      import javax.swing.*;
      public class MenuFrame extends JFrame
      {
      public void initComponents()
      {
      setSize(new java.awt.Dimension(350, 310));

      JMenuBar menuBar = new JMenuBar ();
      JMenu fileMenu = new JMenu ("File");
      JMenu editMenu = new JMenu ("Edit");

      //Populate the menus
      JMenuItem item;
      for (int i=0; i<4; i++)
      {
      item = new JMenuItem ("Item " + i);
      fileMenu.add (item);
      item = new JMenuItem ("Item " + i);
      editMenu.add (item);
      }

      menuBar.add (fileMenu);
      menuBar.add (editMenu);
      setJMenuBar (menuBar);
      }

      public void addNotify()
      {
      super.addNotify();
      initComponents ();
      }
      }
      (Review ID: 102634)
      ======================================================================

            peterz Peter Zhelezniakov
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: