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

undocumented exception on a JPopupMenu.insert(Action a) when index is too high

XMLWordPrintable

    • beta2
    • x86
    • windows_95


      According to the JavaDoc for JPopupMenu.insert(Action a, int index) no
      exceptions are defined. However when you attempt to insert at a index
      that is too high, or too low a IllegallArgumentException is thrown. A sample
      program is attached that demonstrates this.

      Interesting side note is that JPopupMenu.insert(Component c, int index) does
      not demonstrate this problem and just issues a append to the JPopupMenu,
      but that is another potential bug in the api or spec.

      New Merlin JCK tests fail and will need be excluded due to this.

      This may be a spec bug, but I figured I would start with the API.

      Merlin JCK test to exclude:
      api/javax_swing/interactive/JPMenuTests#JPMenuTests0005
      Sample:

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      public class JFrame2 extends javax.swing.JFrame {
      JPopupMenu j;
      JPanel JPanel1;
      MyAction2 myAction33;
      MyAction myAction0;
      public JFrame2() {
      getContentPane().setLayout(null);
      setSize(405,305);
      setVisible(false);
      JPanel1 = new JPanel();
      JPanel1.setBackground(Color.black);
      getContentPane().add(JPanel1);
      JPanel1.setBounds(24,36,360,240);
      j = new JPopupMenu("Hello");
      myAction0 = new MyAction("Click to Insert a action larger than the popup list");
      myAction33 = new MyAction2("Click to Insert a component larger than the popup list");
      j.insert(myAction33,0);
      j.insert(myAction0,1);
      MyMouse myMouse = new MyMouse();
      this.addMouseListener(myMouse);
      }

      static public void main(String args[]) {
      (new JFrame2()).setVisible(true);
      }

      class MyMouse extends MouseAdapter {
      public void mouseReleased(MouseEvent event) {
      if (event.isPopupTrigger())
      j.show(JPanel1, 100, 100);
      }
      }

      class MyAction extends AbstractAction {
           public MyAction(String s) {
           super(s, null);
           }
           public void actionPerformed(ActionEvent e) {
           try {
           j.insert(new MyAction("Action Successfully Added"),2000);
           }
           catch (Exception ee){System.out.println(ee);}
           }
          }
      class MyAction2 extends AbstractAction {
           public MyAction2(String s) {
           super(s, null);
           }
           public void actionPerformed(ActionEvent e) {
           j.insert(new JMenuItem("Component Successfully Added"), 2000);
           }
          }
      }

            peterz Peter Zhelezniakov
            jdixonsunw John Dixon (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: