I have an application that uses a JDialog to get input from the user, and then searching for files, not a browse dialog, but a more specialized one using metadata.
All this works fine. The only problem is I would like to be able to let the user input the search values, press Ok, and receive these values to do the search and some other operations (from the calling class that opened the dialog) without closing the dialog?
It's necessary to do these operations from the calling class, because that's part of a plugin in an editor.
Basically, in short it's sort of like the way a Find dialog works in any editor - the find dialog stays open while you skip from one found item to the next...
It seems like I'm missing something simple, but I cannot see how to do this.
EDIT:
I tried this in a simple test application according to the tutorial suggested by Nick Rippe, but I think I'm misunderstanding it somehow, because I cannot get it to work. I added a field with getters and setters, and then try to get it:
Main class:
public class TestJFrames {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
TestForm frame = new TestForm();
frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);
frame.addPropertyChangeListener("fileSelected", new FileSelectedListener());
frame.setVisible(true);
}
}
class FileSelectedListener implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("TEST");
}
}
From the form class:
private String fileSelected;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.setFileSelected("Test");
}
public String getFileSelected() {
return fileSelected;
}
public void setFileSelected(String fileSelected) {
this.fileSelected = fileSelected;
}
I ended up finding a different solution. Posting it here if it could help someone else with a similar difficulty:
It hit me that I could listen to the button event from the calling class, by registering it as a listener to the dialog class. I pretty much followed this example: Create a custom event in Java