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

Default button is activated even when it is invisible

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 7, 9
    • client-libs
    • None
    • b124
    • generic
    • generic

      If the default button is set, pressing Enter usually actives it.
      However it is activated even when the button is invisible.

      Expected: default button shouldn't activate when it is invisible
      Actual: it works even when it is invisible

      Step to reproduce:
      - Run the test
      - Press Enter
      - See the output in the console

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

      public class DefaultButtonTest {

          private static void createGui() {
              final JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              
              JButton button = new JButton("Default button");
              button.setDefaultCapable(true);
              button.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      System.out.println("DefaultButtonTest.actionPerformed");
                  }
              });

              frame.add(button);
              button.setVisible(false);

              frame.getRootPane().setDefaultButton(button);

              frame.setSize(200, 200);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
          }

          public static void main(String[] args) throws Exception {
              SwingUtilities.invokeAndWait(new Runnable() {
                  public void run() {
                      DefaultButtonTest.createGui();
                  }
              });
          }
      }

            aghaisas Ajit Ghaisas
            alexp Alexander Potochkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: