I use JDateChooser to edit dates in my form.
Short version: I need to distinguish between user date edit and programmatical property change on a JDateChooser.
Workaround: I've found a protected JDateChooser property named dateSelected which is exactly what I need (afaics there is no getter) so probably I'd have to make my own extended JDateChooser class and make a getter for this property. The problem here is that I want to have this custom version to be draggable from the Netbeans Palette and my custom JDateChooser won't be.
Long version: First I get a date from my database and I use the JDateChooser's setDate() method to set the date in the GUI. I want to edit database's date when user picks a new date with the chooser. To do that i listen for a PropertyChange event on the JDateChooser object (looking for the "date" change). After settig the new date in the database, I want to refresh the data (I get the whole record from the database) and I set the date from the database (if there was any error, it gets set back to whatever is in the database at the moment).
The problem is that when I set the date from the database, the same event is fired whe user changes date and then my "refresh" mechanism updates the JDateChooser field and I get infinite loop.
My existing (simplified) code (netbeans):
private void dataStartuChooserPropertyChange(java.beans.PropertyChangeEvent evt) {
if ("date".equals(evt.getPropertyName())) {
JDateChooser wybieraczDat = (JDateChooser) evt.getSource();
updateDatabaseField(wybieraczDat.getDate());
}
}