Skip to main content

JXDatePicker does not lose focus.

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2007-06-12

Hi everyone,
My Swing application has two JXDatePicker components and a JButton, all of them inside a JPanel. When the user selects a range of dates (From and To) and presses the Apply button, the applicaton query the database and display the results in a JXTable on the same screen. I added a DocumentListener on each JXDatePicker component, so whenever the user inserts or deletes a character it checks if the text entered is a date. If so, it checks if the other JXDatePicker has a valid date too or just a null value. In case that both input texts are dates (not null), the Apply button is enabled. If one those dates becomes invalid again (due to user hand editing or deleting them), the Apply button is disabled. When the button is pressed, it then validates that the 'From' date is lesser or equal than the 'To' date. If it is, I query the database.
Here is the problem: the first date is selected, then the second date is selected and everything goes fine. But when I press the Apply button, instead of being pressed, it just gains focus and it has to be pressed again in order to fire the actionPerformed event. So I'd need to press that button twice for the query to be executed. What I need is that button to be pressed just once. I think it could be a focus problem, but I'm not sure. If someone could give me a hand, I will really appreciate it.
P.S. I've also published the same question in Oracle forums but no one answered. I realized this is the apropriate place to ask because SwingX is a project.
Thank you,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-06-08

Can you please provide a small, runnable demo?