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

Windows: Disabled components consumes some of the mouse events

XMLWordPrintable

    • generic
    • generic

      Run the test below. It has three columns :
      1)ordinary components
      2)disabled components
      3) non-editable components.

      When running on XAWT/Motif pressing the mouse over any of disabled component doesn't result in firing the appropriate event. Although that perfectly happen on Windows.
      Some of the events like MOUSE_EXIT/MOUSE_ENTER are still happening on XAWT.
      import java.awt.event.*;
      import java.awt.*;
      import java.io.*;
      import java.util.Vector;
      import java.util.Enumeration;

      public class DisabledEvent
      {
          static Vector containers = new Vector();
          static Vector disabledContainers = new Vector();
          static Vector uneditableTextComponents = new Vector();
          public static Panel addComponentsIntoPanel(boolean enabled, boolean editable){
              TextField tf = new TextField("TextField");
              TextArea ta = new TextArea("TextArea", 10, 10);
              Choice levelChooser = new Choice();
              levelChooser.add("Item #1");
              levelChooser.add("Item #2");
              Button b = new Button("BUTTON");
              Label label = new Label("LABEL");
              List list = new List(4, false);
              list.add("one");
              list.add("two");
              list.add("three");
              Checkbox chb = new Checkbox();
              Scrollbar sb = new Scrollbar(Scrollbar.HORIZONTAL);
              ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
              sp.add(new TextArea("this is a textarea in scrollpane"));
              sp.setSize(200, 200);
              Canvas canvas = new Canvas();
              canvas.setSize(100, 100);
              
              //add popup menu to Button
              final PopupMenu pm = new PopupMenu();
              MenuItem i1 = new MenuItem("Item1");
              MenuItem i2 = new MenuItem("Item2");
              MenuItem i3 = new MenuItem("Item3");
              i3.setEnabled(false);
              pm.add(i1);
              pm.add(i2);
              pm.add(i3);
              canvas.add(pm);

              ta.add(pm);
              ta.addMouseListener(new java.awt.event.MouseAdapter() {
                      public void mousePressed( MouseEvent me ) {
                          if(me.isPopupTrigger()) {
                              pm.show(me.getComponent(), me.getX(), me.getY());
                          }
                      }
                  });

              Vector vector = containers;


              if (!enabled){
                  vector = disabledContainers;
              } else {
                  if (!editable){
                      vector = uneditableTextComponents;
                  }
              }

              vector.add(tf);
              vector.add(ta);
              if (editable){
                  vector.add(levelChooser);
                  vector.add(b);
                  vector.add(label);
                  vector.add(list);
                  vector.add(chb);
                  vector.add(sb);
                  vector.add(sp);
                  vector.add(canvas);
              } else {
                  tf.setEditable(false);
                  ta.setEditable(false);
              }
              
              Panel panel = new Panel();
              panel.setLayout(new GridLayout(0, 1));
              for (Enumeration e = vector.elements(); e.hasMoreElements();){
                  Component c = (Component)e.nextElement();
                  if (!enabled){
                      c.setEnabled(false);
                  }
                  panel.add(c);
              }
              return panel;
          }

          public static void main(String s[])
          {
              Robot robot;
              Frame testFrame = new Frame("XAWTDifference. Test Frame.");
              testFrame.setLayout(new GridLayout(1, 3));
              testFrame.add(addComponentsIntoPanel(true, true));
              testFrame.add(addComponentsIntoPanel(false, true));
              testFrame.add(addComponentsIntoPanel(true, false));

              try {
                  robot = new Robot();
              }catch (AWTException e){
                  throw new RuntimeException("Unable to create robot:"+e);
              }
              Toolkit toolkit = Toolkit.getDefaultToolkit();
              toolkit.addAWTEventListener(new AWTEventListener(){
                 public void eventDispatched(AWTEvent ev){

                    System.out.println(">> "+ev);
                 }
              }, MouseEvent.BUTTON1_MASK);


              testFrame.pack();
              testFrame.setVisible(true);
          }// main
      }// class

            Unassigned Unassigned
            dav Andrei Dmitriev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: