-
Bug
-
Resolution: Fixed
-
P4
-
7, 9
-
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();
}
});
}
}
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();
}
});
}
}
- relates to
-
JDK-6948021 Need a better control over ActionMap/InputMap feature
-
- Closed
-