Skip to content

Instantly share code, notes, and snippets.

@RustyKnight
Created May 18, 2018 21:49
Show Gist options
  • Save RustyKnight/1a85ff63d8cb16d197b8ea19ebf214ed to your computer and use it in GitHub Desktop.
Save RustyKnight/1a85ff63d8cb16d197b8ea19ebf214ed to your computer and use it in GitHub Desktop.
Simple test of invoke and wait
JFileChooser chooser = new JFileChooser();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
chooser.showOpenDialog(null);
JOptionPane.showMessageDialog(null, "Bananas");
}
});
System.out.println("Bang");
System.out.println(chooser.getSelectedFile());
} catch (InterruptedException | InvocationTargetException ex) {
ex.printStackTrace();
}
}
});
t.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment