Problem: JButton requires two clicks to execute.
Apparent Cause: Adding a DocumentListener to a JFormattedTextField
Background:
I created form inside of a JDialog. The form contained a JFormattedTextField, OK and Cancel buttons and a JComboBox. The JFormattedTextField filters text, not format it. Everything worked as expected until I added a DocumentListener to the JFormattedTextField. When that happened, I noticed that it takes two clicks on the OK button for it to execute its actionPerformed() method. Visually the JButton appeared to be clicked by displaying the "mouse over", "mouse pressed" and "mouse released" events, but nothing happened as a result of clicking the button.
I replaced the JFormattedTextField with a JTextField. To ensure that the JTextField only allows numeric text, I attached a DocumentListener to it. Since my text field needed to filter user input and not format it, this is what I should have used anyway.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment