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

swing-1.0.1: problem at JMenu.add() after JMenu.remove()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 1.1.6, 1.2.0
    • client-libs
    • swing1.1
    • x86, sparc
    • solaris_2.5.1, windows_nt



      Name: rk38400 Date: 05/20/98


      1. Create JMenu with 2 JMenuItem's
         remove first item and add 3rd and 4th ones->
         visible are only 2 items: move mouse cursor
         'around' the first one->change btw. names of
         2nd and 3rd created item in first visible
         JMenuItem
         position is visible
         Example is with JPopupMenu but effect is same
         for JMenu. In difference, removeAll() of
         JMenu works as expected.

      2. Following code induces problem:

      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;

      class Main {

        public static void main(String[] args) {
              Main mm = new Main();
        }

        private JPopupMenu m;
        private JMenuItem m1;
        private JButton l;

        public Main() {
                      JFrame fr = new JFrame("Hello");
                      l = new JButton("Green");
                      l.addActionListener(new ListenerB());
                      fr.getContentPane().add(l);
                      fr.pack();
                      fr.show();
                      m = new JPopupMenu("Yellow");
                      fr.getContentPane().add(m);
                      m1 = new JMenuItem("1");
                      m.add(m1);
                      JMenuItem m2 = new JMenuItem("2");
                      m2.addActionListener(new Listener2());
                      m.add(m2);
       }

       class Listener2 implements ActionListener {
                      public void actionPerformed(ActionEvent e) {
                              m.remove(m1);
                              m.add(new JMenuItem("4"));
                              m.add(new JMenuItem("3"));
                      }
        }

       class ListenerB implements ActionListener {
                      public void actionPerformed(ActionEvent e) {
                              m.show(l,20,20);
                      }
        }
      }

        in comparison, the following works fine (without
        swing):

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

      class Main {

        public static void main(String[] args) {
              Main mm = new Main();
        }

       private PopupMenu m;
       private MenuItem m1;
       private Button l;

       public Main() {
                      Frame fr = new Frame("Hello");
                      l = new Button("Green");
                      l.addActionListener(new ListenerB());
                      fr.add(l);
                      fr.pack();
                      fr.show();
                      m = new PopupMenu("Yellow");
                      fr.add(m);
                      m1 = new MenuItem("1");
                      m.add(m1);
                      MenuItem m2 = new MenuItem("2");
                      m2.addActionListener(new Listener2());
                      m.add(m2);
       }

       class Listener2 implements ActionListener {
                      public void actionPerformed(ActionEvent e) {
                              m.remove(m1);
                              m.add(new MenuItem("4"));
                              m.add(new MenuItem("3"));
                      }
        }

       class ListenerB implements ActionListener {
                      public void actionPerformed(ActionEvent e) {
                              m.show(l,20,20);
                      }
        }
      }

         Problem also occured under HP UX.

      3. Error messages did not appear.

      4. -

      5. -
      (Review ID: 30770)
      ======================================================================

            gsaab Georges Saab
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: