Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36783
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Can you lock a dialog and continue? |
| Date | 2017-06-30 14:33 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <oj68qi$ohv$1@dont-email.me> (permalink) |
| References | <34333fbb-4b83-454b-9395-4efaa019e95e@googlegroups.com> <fc1ca100-85e5-49fc-9f28-f961288b34e9@googlegroups.com> |
On 6/30/2017 13:34, Eric Douglas wrote:
> I want the user to wait, not the program.
> I want to be able to execute a background process which may take a minute, and update controls on the screen which may take a minute possibly a table with a lot of values, and not let the user interact until any of that is done, and display a message with JProgressBar while they wait.
>
Use a modal dialog to stop user input. Use a thread to do your work and
then update your GUI/JProgressBar on the EDT.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test9 extends JFrame {
private JProgressBar bar = new
JProgressBar(SwingConstants.HORIZONTAL,0,10);
public test9() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JButton start = new JButton("Start");
start.addActionListener(event -> {
JDialog dialog = new JDialog(this,true);
dialog.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent we) {
new Thread(() -> {
int n = 0;
while (n < 11) {
int q = n;
EventQueue.invokeLater(() -> bar.setValue(q));
try { Thread.sleep(1000);
} catch (InterruptedException ie) { }
++n;
}
dialog.dispose();
}).start();
}
});
dialog.add(bar,BorderLayout.CENTER);
dialog.pack();
dialog.setVisible(true);
});
add(start,BorderLayout.CENTER);
pack();
setVisible(true);
}
public static void main(String... args) {
EventQueue.invokeLater(() -> new test9());
}
}
--
Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can you lock a dialog and continue? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 10:35 -0700
Re: Can you lock a dialog and continue? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-30 14:24 -0400
Re: Can you lock a dialog and continue? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 11:34 -0700
Re: Can you lock a dialog and continue? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-06-30 14:33 -0500
Re: Can you lock a dialog and continue? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 13:19 -0700
Re: Can you lock a dialog and continue? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-06-30 15:35 -0500
Re: Can you lock a dialog and continue? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 13:56 -0700
Re: Can you lock a dialog and continue? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-06-30 15:40 -0500
Re: Can you lock a dialog and continue? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 13:52 -0700
Re: Can you lock a dialog and continue? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-30 21:14 +0000
Re: Can you lock a dialog and continue? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-30 17:19 -0400
csiph-web