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

Disabled Components do not receive MouseEvent

    Details

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

      Description



      Name: bsC130419 Date: 06/28/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)


      When testing my application with JDK 1.4 I noticed that disabled Swing-
      components don't receive any mouse events anymore. This is a different
      behaviour compared to JDK 1.3.1 and therefore a backwards compatibility issue.

      For me it is important to still be able to react on mouse events, even if the
      component is disabled. I one case I want to enable a component when it is
      clicked on. The new situation unnecessarily limits the flexibility of Swing, so
      I hope you will investigate the issue.

        To reproduce the Bug run my very simple code on JDK 1.3 and the on JDK 1.4.
      Each time move over the components and click them and watch the output.

      (Also the layout of the components is different on JDK 1.4, but here I think it
      is an improvement over JDK 1.3)

      /********* Demonstration of MouseEvent bug with disabled components

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class EventDemo extends JFrame {
        // these are the two JComponents that should receive the events
        JTextPane jTextPane = new JTextPane();
        JButton jButton = new JButton();

        public EventDemo() {
          this.getContentPane().setLayout(new GridBagLayout());
          jTextPane.setText("jTextPane");
          jTextPane.addMouseListener(new EventDemo_jTextPane_mouseAdapter(this));
          jTextPane.setEnabled(false); // important
          jButton.setText("jButton"); // important
          jButton.addMouseListener(new EventDemo_jButton_mouseAdapter(this));
          jButton.addMouseMotionListener(new EventDemo_jButton_mouseMotionAdapter
      (this));
          jButton.setEnabled(false);
          this.getContentPane().add(jTextPane, new GridBagConstraints(0, 0, 1, 1,
      0.0, 0.0
                  ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new
      Insets(0, 0, 0, 0), 0, 0));
          this.getContentPane().add(jButton, new GridBagConstraints(0, 2, 1, 1, 0.0,
      0.0
                  ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,
      0, 0, 0), 0, 0));
        }

        // method to exit properly; not relevant for demonstration of bug
        protected void processWindowEvent(WindowEvent e) {
          super.processWindowEvent(e);
          if(e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
          }
        }

        public static void main(String[] args) {
          EventDemo demo = new EventDemo();
          // pack and center on screen
          demo.pack();
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          demo.setLocation((screenSize.width - demo.getWidth()) / 2,
      (screenSize.height - demo.getHeight()) / 2);
          demo.setVisible(true);
        }

        // these methods get called when a component receives an event
        // they will just print out the event type and the receiver
        void jTextPane_mouseClicked(MouseEvent e) {
          System.out.println("jTextPane clicked");
        }

        void jButton_mouseClicked(MouseEvent e) {
          System.out.println("jButton clicked");
        }

        void jButton_mousePressed(MouseEvent e) {
          System.out.println("jButton pressed");
        }

        void jButton_mouseReleased(MouseEvent e) {
          System.out.println("jButton released");
        }

        void jButton_mouseEntered(MouseEvent e) {
          System.out.println("jButton entered");
        }

        void jButton_mouseExited(MouseEvent e) {
          System.out.println("jButton exited");
        }

        void jButton_mouseMoved(MouseEvent e) {
          System.out.println("jButton moved");
        }


      }

      class EventDemo_jTextPane_mouseAdapter extends java.awt.event.MouseAdapter {
        EventDemo adaptee;

        EventDemo_jTextPane_mouseAdapter(EventDemo adaptee) {
          this.adaptee = adaptee;
        }
        public void mouseClicked(MouseEvent e) {
          adaptee.jTextPane_mouseClicked(e);
        }
      }

      class EventDemo_jButton_mouseAdapter extends java.awt.event.MouseAdapter {
        EventDemo adaptee;

        EventDemo_jButton_mouseAdapter(EventDemo adaptee) {
          this.adaptee = adaptee;
        }

        public void mouseClicked(MouseEvent e) {
          adaptee.jButton_mouseClicked(e);
        }

        public void mousePressed(MouseEvent e) {
          adaptee.jButton_mousePressed(e);
        }

        public void mouseReleased(MouseEvent e) {
          adaptee.jButton_mouseReleased(e);
        }

        public void mouseEntered(MouseEvent e) {
          adaptee.jButton_mouseEntered(e);
        }

        public void mouseExited(MouseEvent e) {
          adaptee.jButton_mouseExited(e);
        }
      }

      class EventDemo_jButton_mouseMotionAdapter extends
      java.awt.event.MouseMotionAdapter {
        EventDemo adaptee;

        EventDemo_jButton_mouseMotionAdapter(EventDemo adaptee) {
          this.adaptee = adaptee;
        }

        public void mouseMoved(MouseEvent e) {
          adaptee.jButton_mouseMoved(e);
        }
      }
      (Review ID: 127529)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bchristi Brent Christian
                Reporter:
                bstrathesunw Bill Strathearn (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: