mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Use SwingUtilities to avoid deadlock in GUI mini app
This commit is contained in:
parent
0ea0ecddc5
commit
bdc7c26526
|
@ -38,6 +38,7 @@ import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.WindowConstants;
|
import javax.swing.WindowConstants;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
|
|
||||||
|
@ -69,16 +70,26 @@ public final class GUIRunner extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws MalformedURLException {
|
public static void main(String[] args) throws MalformedURLException {
|
||||||
GUIRunner runner = new GUIRunner();
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
runner.setVisible(true);
|
public void run() {
|
||||||
runner.chooseImage();
|
GUIRunner runner = new GUIRunner();
|
||||||
|
runner.setVisible(true);
|
||||||
|
runner.chooseImage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void chooseImage() throws MalformedURLException {
|
private void chooseImage() {
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
fileChooser.showOpenDialog(this);
|
fileChooser.showOpenDialog(this);
|
||||||
Path file = fileChooser.getSelectedFile().toPath();
|
Path file = fileChooser.getSelectedFile().toPath();
|
||||||
Icon imageIcon = new ImageIcon(file.toUri().toURL());
|
Icon imageIcon;
|
||||||
|
try {
|
||||||
|
imageIcon = new ImageIcon(file.toUri().toURL());
|
||||||
|
} catch (MalformedURLException muee) {
|
||||||
|
throw new IllegalArgumentException(muee);
|
||||||
|
}
|
||||||
setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight() + 100);
|
setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight() + 100);
|
||||||
imageLabel.setIcon(imageIcon);
|
imageLabel.setIcon(imageIcon);
|
||||||
String decodeText = getDecodeText(file);
|
String decodeText = getDecodeText(file);
|
||||||
|
|
Loading…
Reference in a new issue