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

Hang with JPopupMenu in Merlin

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • client-libs
    • beta2
    • sparc
    • solaris_7

      This is an offshoot of bugid 4411089. The crash that bug report
      described was fixed in Ladybird, but does not exist in Merlin.
      Unfortunately, other problems do exist in Merlin: the application doesn't
      draw correctly, the buttons are non-responsive, and it hangs.

      I tested with Merlin build 53. Please compare with the way it works in 1.3


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

      public class JPopupCoreDemo extends JWindow
      {
        private JButton btn1;
        private JButton btn2;
        private JButton btn3;

        private JPopupMenu popup;
        private JMenu menu;
        private JMenuItem[] mainMenuItems;
        private JMenuItem[] subMenuItems;

        public JPopupCoreDemo()
        {
          super();
          
          menu = new JMenu("Menu 1");
          
          for(int i=0; i<5; i++)
          {
            menu.add( "Sub MenuItem " + Integer.toString(i) );
            if( (0 != i) && (0 == i%2) )
              menu.addSeparator();
          }

          popup = new JPopupMenu("Demo JPopupMenu");
          popup.setLightWeightPopupEnabled(true);
          popup.add( menu );
          popup.addSeparator();

          ActionListener listener = new ActionListener()
            {
              public void actionPerformed (ActionEvent evt)
              {
                System.out.println("Doing something");
              }
            };
          
          for(int j=0; j<10; j++)
          {
            JMenuItem mi = popup.add( "Main MenuItem " + Integer.toString(j) );
            mi.addActionListener( listener );
            
            if( (0 != j) && (0 == j%2) )
              popup.addSeparator();
          }

          btn1 = new JButton("Button1");
          btn1.setToolTipText("Show JPopupMenu");
          btn1.addActionListener( new ActionListener()
            {
              public void actionPerformed (ActionEvent evt)
              {
                 popup.show( btn1, 0, btn1.getSize().height );
              }
            });

          btn2 = new JButton("Button2");
          btn2.setToolTipText("Show JPopupMenu");
          btn2.addActionListener( new ActionListener()
            {
              public void actionPerformed (ActionEvent evt)
              {
                 popup.show( btn2, 0, btn2.getSize().height );
              }
            });

          btn3 = new JButton("Button3");
          btn3.setToolTipText("Show JPopupMenu");
          btn3.addActionListener( new ActionListener()
            {
              public void actionPerformed (ActionEvent evt)
              {
                 popup.show( btn3, 0, btn3.getSize().height );
              }
            });

          Box bx = Box.createHorizontalBox();
          bx.add(btn1);
          bx.add(Box.createHorizontalGlue());
          bx.add(btn2);
          bx.add(Box.createHorizontalGlue());
          bx.add(btn3);

          super.setContentPane( bx );

          MouseAdapter mouseAdp = new MouseAdapter()
            {
              public void mouseClicked(MouseEvent e)
              {
                if( (( e.getModifiers() & e.BUTTON3_MASK ) != 0 ) ||
                    e.isPopupTrigger() )
                {
                  popup.show( e.getComponent(), e.getX(), e.getY() );
                }
              }
            };

          super.addMouseListener(mouseAdp);

          pack();

          super.setSize( super.getToolkit().getScreenSize().width,
                         super.getSize().height );

          super.setVisible(true);
        }

        public static void main(String[] arg)
        {
          new JPopupCoreDemo();
        }
        
      }

            dmikhalksunw Denis Mikhalkin (Inactive)
            ehawkessunw Eric Hawkes (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: