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

win32: setEnabled(false) on JFrame doesn't disable keyboard events

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.2.2
    • client-libs
    • x86
    • windows_95

      Name: krT82822 Date: 07/03/99


      [win32-specific, as of JDK 1.2.2 RC1 --kevin.ryan@eng, 7/3/99]
      (see also bug # 4223366)
      [Filed against 1.2 FCS, but have revised the version # to 1.2.2, since problem still exists in 1.2.2 RC1]

      When I disable a JFrame with setEnabled(false)
      only MouseEvents are supressed. The keyboard still works.

      In the example below, press the 'disable'-button to disable
      the JFrame. After that you can still set the focus on any of
      its components by using the tab-key.

      On the component with the focus the keyboard still works normaly:
      you can enter text in the JTextField,
      press the button using the spacebar.

      You can also use the mnemonics in a disabled frame.

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

      // A test for disabling a JFrame
      // The setEnabled(false) does not block keyboard-Events
      public class TestFrame extends JFrame {
              private JButton enable = new JButton("enable");
              private JButton disable = new JButton("disable");
              private JTextField text = new JTextField();

              public TestFrame() {
                      enable.addActionListener( new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                      TestFrame.this.setEnabled(true);
                              }
                      });
                      enable.setMnemonic('e');

                      disable.addActionListener( new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                      TestFrame.this.setEnabled(false);
                              }
                      });

                      getContentPane().add(enable, BorderLayout.NORTH);
                      getContentPane().add(text, BorderLayout.CENTER);
                      getContentPane().add(disable, BorderLayout.SOUTH);
              }

              public static void main(String[] args) {
                      TestFrame testFrame = new TestFrame();
                      testFrame.pack();
                      testFrame.setVisible(true);
              }
      }


      It looks like a bug in the peer-class of the frame.
      (Review ID: 53599)
      ======================================================================

            son Oleg Sukhodolsky (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: