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


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

Re: Can you lock a dialog and continue?

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 15:35 -0500
Organization A noiseless patient Spider
Message-ID <oj6cg4$55h$1@dont-email.me> (permalink)
References <34333fbb-4b83-454b-9395-4efaa019e95e@googlegroups.com> <fc1ca100-85e5-49fc-9f28-f961288b34e9@googlegroups.com> <oj68qi$ohv$1@dont-email.me> <c4b02e21-c034-43a5-be42-c5b2d5276a83@googlegroups.com>

Show all headers | View raw


On 6/30/2017 15:19, Eric Douglas wrote:
> On Friday, June 30, 2017 at 3:33:27 PM UTC-4, Knute Johnson wrote:
>> ...
> 
> I was thinking more of a reusable process window I can show and hide from anywhere that could take a second?
> My test with 2 dialogs just disabling so I can keep running, rather than stopping for user input and putting everything inside the window open listener, sort of works.  Why can't I add new objects to the first window?
> 
> import java.awt.BorderLayout;
> import java.awt.EventQueue;
> import java.awt.Toolkit;
> import java.awt.Window;
> import java.awt.event.ActionEvent;
> import java.awt.event.ActionListener;
> import java.awt.event.WindowAdapter;
> import java.awt.event.WindowEvent;
> 
> import javax.swing.JButton;
> import javax.swing.JDialog;
> import javax.swing.JLabel;
> import javax.swing.JProgressBar;
> import javax.swing.SwingWorker;
> 
> public class WindowTest {
> 
>       public static void main(final String[] args) {
>            EventQueue.invokeLater(new Runnable() {
> 
>                 @Override
>                 public void run() {
>                      final JDialog win1 = new JDialog();
>                      win1.setLayout(new BorderLayout());
>                      win1.addWindowListener(new WindowAdapter() {
> 
>                           @Override
>                           public void windowClosing(final WindowEvent e) {
>                                e.getWindow().dispose();
>                           }
>                      });
>                      win1.setSize(400, 300);
>                      final JButton btn1 = new JButton("button one");
>                      btn1.addActionListener(new ActionListener() {
> 
>                           @Override
>                           public void actionPerformed(final ActionEvent e) {
>                                System.out.println("clicked one");
>                           }
> 
>                      });
>                      win1.getContentPane().add(btn1, BorderLayout.PAGE_START);
>                      win1.setVisible(true);
>                      System.out.println("win 1 visible");
>                      final JDialog win2 = new JDialog(win1);
>                      win2.addWindowListener(new WindowAdapter() {
> 
>                           @Override
>                           public void windowOpened(final WindowEvent e) {
>                                final Window curWin = e.getWindow();
>                                final Window parent = curWin.getOwner();
>                                if (parent != null) {
>                                     parent.setEnabled(false);
>                                }
>                           }
> 
>                           @Override
>                           public void windowClosing(final WindowEvent e) {
>                                final Window curWin = e.getWindow();
>                                final Window parent = curWin.getOwner();
>                                if (parent != null) {
>                                     parent.setEnabled(true);
>                                }
>                                curWin.dispose();
>                           }
>                      });
>                      // This works if I execute it here
>                      // win1.getContentPane().add(new JLabel("Updated"),BorderLayout.PAGE_END);
>                      win2.setSize(400, 150);
>                      win2.setLocationRelativeTo(win1);
>                      win2.setLayout(new BorderLayout());
>                      final JProgressBar pb = new JProgressBar();
>                      pb.setString("Hang on we're updating");
>                      pb.setStringPainted(true);
>                      pb.setIndeterminate(true);
>                      win2.add(pb,BorderLayout.CENTER);
>                      final JButton btn2 = new JButton("close me");
>                      btn2.addActionListener(new ActionListener() {
> 
>                           @Override
>                           public void actionPerformed(final ActionEvent e) {
>                                System.out.println("clicked two");
>                                final WindowEvent wev = new WindowEvent(win2, WindowEvent.WINDOW_CLOSING);
>                                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
>                           }
> 
>                      });
>                      btn2.setVisible(false);
>                      win2.getContentPane().add(btn2,BorderLayout.PAGE_END);
>                      win2.dispose();
>                      win2.setUndecorated(true);
>                      win2.setVisible(true);
>                      System.out.println("win 2 visible");
>                      final SwingWorker sw = new SwingWorker() {
> 
>                           @Override
>                           protected Object doInBackground() throws Exception {
>                                Thread.sleep(1000);
>                                return null;
>                           }
> 
>                           @Override
>                           public void done() {
>                                // button can display because it's already added
>                                btn2.setVisible(true);
>                                // Doesn't show up when I execute it here
>                                win1.getContentPane().add(new JLabel("Updated"), BorderLayout.PAGE_END);
>                                System.out.println("done");
>                           }
>                      };
>                      sw.execute();
>                 }
>            });
>       }
> }
> 

win1.validate();		// see Container.validate()

Are you using some old version of Java?  You don't need all those finals 
or the getContentPane() calls any more.


-- 

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