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

Can't properly handle event listeners on compound components

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.5, 1.1.6, 1.2.0, 1.2.1
    • client-libs
    • generic, x86
    • generic, windows_95, windows_nt

      I changed the summary of this bug to reflect the real problem. The real problem is that compound components can't have listeners attached to them in a meaningful way. If someone attaches a mouseListener to a JComboBox, they won't receive any events when the user clicks in the arrow button. This is confusing a number of developers who expect the component to act as a single component, not a collection of smaller ones.
      tom.santos@eng 1998-04-13
      ============

      Name: rk38400 Date: 04/11/98
      I need to add a mouselistener to a JComboBox in order to
      pop up a menu when e.isPopupTrigger(). This works for
      Windows and Motif L&F but when Metal L&F is loaded, no
      mouse events are received.
      (Review ID: 26387)
      ======================================================================


      //------------------------Move.java------------------------
      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;

      public class Move
      {
          int moveCount = 0;
          int dragCount = 0;

          public static void main(String[] args)
          {
              new Move();
          }
          public Move()
          {
              String[] teams = {"Maple Leafs", "Devils", "Canucks",
                      "Red Wings", "Rangers", "Avalanche"};
              JComboBox combo = new JComboBox(teams);
              JFrame f = new JFrame("Test MouseMotionListener");
              f.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
              });
              MouseMotionListener mListener = new MouseMotionListener(){
                  public void mouseDragged(MouseEvent e) {
                      System.out.println("Mouse Dragged " + (dragCount++));
                  }
                  public void mouseMoved(MouseEvent e) {
                      System.out.println("Mouse Moved " + (moveCount++));
                  }
              };
              combo.addMouseMotionListener(mListener);
              f.getContentPane().setLayout(new GridLayout(2,1));
              Button b1 = new Button("Some Button");
              b1.addMouseMotionListener(mListener);
              f.getContentPane().add(b1);
              f.getContentPane().add(combo);
              f.setSize(500,300);
              f.show();
          }
      }

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: