Skip to content

Instantly share code, notes, and snippets.

@sarxos
Created May 24, 2016 07:09
Show Gist options
  • Select an option

  • Save sarxos/a53255d60745e182de87c3bb81d8a242 to your computer and use it in GitHub Desktop.

Select an option

Save sarxos/a53255d60745e182de87c3bb81d8a242 to your computer and use it in GitHub Desktop.
void actionPerformed(..) {
Thread t = new Thread(new Runnable() {
public void run() {
// capture qr, this will not block because it's in thread,
// do all long running/blocking operations here, in this
// thread
final String qr = captureQrCode();
// schedule swing update when edt is ready to be used,
// this will bring you back to the edt (and blocking world),
// but since this is easy operation, gui should not freez
SwingUtilities.invokeLater(new Runnable() {
public void run() {
doSomethingWithQrCode(qr);
}
});
}
});
t.setDaemon(true);
t.start();
}
void doSomethingWithQrCode(String qr) {
// do something with QR code, update gui, this should
// be non-blocking and fast operation, otherwise gui
// will be freezing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment