Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36783

Re: Can you lock a dialog and continue?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject Re: Can you lock a dialog and continue?
Date Fri, 30 Jun 2017 14:33:08 -0500
Organization A noiseless patient Spider
Lines 56
Message-ID <oj68qi$ohv$1@dont-email.me> (permalink)
References <34333fbb-4b83-454b-9395-4efaa019e95e@googlegroups.com> <fc1ca100-85e5-49fc-9f28-f961288b34e9@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Fri, 30 Jun 2017 19:29:23 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="841531b0e9e92185f374178ee5a1d0c6"; logging-data="25151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//BnSLq3t1kD490co3iPgV"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1
In-Reply-To <fc1ca100-85e5-49fc-9f28-f961288b34e9@googlegroups.com>
Content-Language en-US
Cancel-Lock sha1:Tn6aic73GjraAYB0LpaaxFPt0Ho=
Xref csiph.com comp.lang.java.programmer:36783

Show key headers only | View raw


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


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