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

Selecting MenuItem in Popup not doing action. Works is 1.18.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.3.0
    • Fix Version/s: 1.4.0
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: yyT116575 Date: 12/04/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


      When selecting a Menu Item in a popup, the action listender that's
      added to the menu item is not called. Here's a simple program
      for demonstration:

      Note, actionPerformed is never called when the MenuItem is clicked.

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

      public class PopupBug extends Frame {
          private PopupBugCanvas fpc;

          public PopupBug() {
              fpc = new PopupBugCanvas();

              add(fpc);

              /*
              ScrollPane pane = new ScrollPane();
              pane.setSize(400,400);
              pane.add(fpc);
              add(pane);
              */
          }

          public static void main(String[] args) {
              PopupBug fp = new PopupBug();

              fp.pack();
              fp.show();
          }
      }

      class PopupBugCanvas extends Canvas implements ActionListener {
          public PopupMenu popup;

          public PopupBugCanvas() {
              this.enableEvents(AWTEvent.MOUSE_EVENT_MASK);

              setSize(400,400);

              String[] labels =
                  new String[] {
                      "Test Button 1"
                  };

              String[] commands =
                  new String[] {
                      "c1"
                  };

              popup = new PopupMenu();

              int i;

              for(i=0; i < labels.length; i++) {
                  MenuItem mi = new MenuItem(labels[i]);
                  mi.setActionCommand(commands[i]);
                  mi.addActionListener(this);
                  popup.add(mi);
              }

              this.add(popup);
          }

          public void paint(Graphics g) {
              Color cl = new Color(0xff,0,0);

              setBackground(cl);
              g.drawString("right click", 20, 20);
          }

          public void processMouseEvent(MouseEvent e) {
              if (e.isPopupTrigger()) {
                  popup.show(this, e.getX(), e.getY());
              }
              else if (e.getID() == MouseEvent.MOUSE_PRESSED) {
                  System.err.println("In mouse_pressed\n");
              }
              else super.processMouseEvent(e);
          }

          public void actionPerformed(ActionEvent e) {
              String command = e.getActionCommand();
              System.err.println("command = "+command+"\n");

              if (command.equals("c1")) {
                  System.err.println("command 1\n");
              }
              else if (command.equals("c2")) {
                  System.err.println("command 2\n");
              }
          }
      }
      (Review ID: 113098)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmikhalksunw Denis Mikhalkin (Inactive)
                Reporter:
                yyoungsunw Yung-ching Young (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: