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

Problem with PopupMenu in Windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs
    • x86
    • windows_nt



      Name: vi73552 Date: 03/23/99


      //Consider the following code :

      import java.awt.* ;
      import java.awt.event.* ;

      public class Bug extends Frame implements ActionListener
      {
      private PopupMenu mnuPop ;
      private Button btn ;
      public Bug ()
      {
      super ("PopupMenu bug") ;
      Menu mnu ;
      mnuPop = new PopupMenu () ;
      mnu = new Menu ("1st SubMenu") ;
      mnu.add (new MenuItem ("1st MenuItem")) ;
      mnu.add (new MenuItem ("2nd MenuItem")) ;
      mnu.add (new MenuItem ("3rd MenuItem")) ;
      mnuPop.add (mnu) ;
      add (btn = new Button("Nix"),BorderLayout.CENTER) ;
      btn.addActionListener (this) ;
      btn.add (mnuPop) ;
      setSize (100, 100) ;
      show () ;
      }

      public void actionPerformed (ActionEvent ae)
      {
      mnuPop.show (btn, 0, 0) ;

      /* this should display a menu with the proper text in all menus and menuitems. Instead, I get a menu made of buttons, and all buttons have the same caption, i.e "Nix". I'm getting

      +--------+--------+ +---------------+--------------+
      | Nix >| Nix | | 1st SubMenu >| 1st MenuItem |
      +--------+--------+ +---------------+--------------+
               | Nix | instead of | 2nd MenuItem |
               +--------+ +--------------+
               | Nix | | 3rd MenuItem |
               +--------+ +--------------+
      .
      If, on the other hand, I add the menu to the frame itself, without creating the button and adding a MouseListener which will show the menu on mousePressed, it works fine.
      */
      }

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

      }
      /* Conclusion : I guess 'PopupMenu'-s weren't meant to be added to buttons ... */
      (Review ID: 55532)
      ======================================================================

            mmartaksunw Michael Martak (Inactive)
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: