Reputation: 217
Looking to get the current file path so need to catch an event when there is a value change in the "Look In:" combobox in the JFileChooser below. I would like to fire the same event when the folder is selected from the list so I can keep updating the file path.
I'm not looking for the event when the Open of Cancel buttons are pressed!
Any ideas?
Upvotes: 2
Views: 447
Reputation: 417797
When you change the folder in the "Look in:"
combo box, only one PropertyChangeEvent
is fired with the property name: JFileChooser.DIRECTORY_CHANGED_PROPERTY
.
You can use this little code sample to test what property change events are fired in the background when you click around in the JFileChooser
:
JFileChooser fc = new JFileChooser();
fc.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("Prop Change Event: " + evt.getPropertyName());
if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(
evt.getPropertyName())) {
// This is the event you're looking for
}
}
});
Note though that changing the current folder in the "Look in:"
combo box is not the only event that generates a PropertyChangeEvent
with property name DIRECTORY_CHANGED_PROPERTY
, for example if you double click on a folder in the file list, that also generates this event (amongst other events like SELECTED_FILE_CHANGED_PROPERTY
).
Upvotes: 2