Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 533
  • Last Modified:

fixing location, ie. making dialog unmovable

Hi experts,

I was wondering how to make a JDialog unmovable.
Any ideas?

Dan
0
dbrownell83
Asked:
dbrownell83
  • 32
  • 13
1 Solution
 
dbrownell83Author Commented:
sorry, 'immobile'
0
 
objectsCommented:
don't think you can.

Why use a window if you don't want it to be movable?
Perhaps look at using a glass pane instead.
0
 
dbrownell83Author Commented:
well, the problem is I've got 1 main JFrame,
with a bunch of JDialogs open.

So if I used the glasspane, it would still be under the open jdialogs.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
why exactly is it you don't want them to be movable?
0
 
dbrownell83Author Commented:
i think my problem's with threads...
In the following code, the glasspane stuff just doesnt happen.

                         i=0;
                        while (itr.hasNext()) {
                            final MyClass d = (MyClass)itr.next();
                           
                              openRunners[i] = (new Thread(new Runnable() {
                                  public void run() {
                                      d.setGlassPane(new JLabel("Please wait for this campaign to stop..."));
                                      d.fireODialerUIStopEvent();
                                  }                            
                              }));

                              openRunners[i].start();
                              i++;
                        }

                       
                        for (i = 0; i < openRunners.length; i++) {
                            try {
                                openRunners[i].join();
                            } catch (InterruptedException e) {}
                        }
   
0
 
dbrownell83Author Commented:
Well before I was trying to make a 'Please Wait' message box, but it blocked if I made it modal, and it didnt show any content if I made it non-modal.... so if I made the message box unmovable, then at least I could prevent the user from moving it around, messying the UI, (making the JFrame look like the app has frozen).
0
 
dbrownell83Author Commented:
to clarify, the 'please wait' box waits for the open Jdialogs to finish and close
0
 
objectsCommented:
sounds like you could make it modal, and do your processing in a seperate thread.
0
 
dbrownell83Author Commented:
if i make it modal,
and put the setVisible(true) in a thread,
it doesnt draw correctly.
0
 
dbrownell83Author Commented:
or wait, that was non-modal
lemme check modal
0
 
dbrownell83Author Commented:
still nope...
the dialog is just an outline of a dialog, with the title, but gray content as though its frozen
0
 
objectsCommented:
> and put the setVisible(true) in a thread

setVisible() should be called from the EDT
0
 
objectsCommented:
0
 
dbrownell83Author Commented:
ok, i switched the thread to a SwingUtilities.invokeLater call...
and... now it won't even open the dialog.
0
 
dbrownell83Author Commented:
i can't call invokeandwait because the code is already from the EDT i think
0
 
dbrownell83Author Commented:
i don't trust that swingworker class either
0
 
objectsCommented:
> i don't trust that swingworker class either

how come?

Think you need to post some of your code so I can see whats going on.
0
 
dbrownell83Author Commented:
well i made a class, but this is an earlier simpler version, for understanding's sake:

 
                        final JOptionPane pane = new JOptionPane("Please wait for runners to close...",
                                JOptionPane.INFORMATION_MESSAGE);
                       
                        final JDialog dialog = new JDialog(mFrame, "Please wait...", true);
                        dialog.setContentPane(pane);
                       
                        dialog.setLocation(ODialerUIPreferences.getDataSourcePosition().x,
                                           ODialerUIPreferences.getDataSourcePosition().y);
                        dialog.pack();
                        dialog.setVisible(true);
                        dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));                                

...
(the thread code in the earlier post)
...


                        dialog.setVisible(false);




depending on what I shove around that setVisible(true), the GUI will either choke (though correctly join my threads), or will show the dialog, but block forever.
0
 
dbrownell83Author Commented:
i don't trust the swingworker class because i'm sure there's gotta be a way to do it without it
0
 
objectsCommented:
>                dialog.setVisible(true);

this will block the thread (as you are experiencing)

So what you need to do is make that call (using invokeLater) from your processing thread, that way the processing will not be blocked.

0
 
dbrownell83Author Commented:
hmm... maybe.

right now i'm making lots of little threads, so i'll see if making one big thread that calls it will work.
I doubt it, of course, since why should calling invokeLater even later than I'm calling it make an improvement?
but i'll try.
0
 
dbrownell83Author Commented:
(and why won't it just block my processing thread)
0
 
objectsCommented:
> (and why won't it just block my processing thread)

because the call will be made on the EDT, and not your processing thread.
0
 
dbrownell83Author Commented:
sorry, but it doesnt work.

                        final JOptionPane pane = new JOptionPane("Please wait for campaigns to stop...",
                                JOptionPane.INFORMATION_MESSAGE);
                       
                        final JDialog dialog = new JDialog(mFrame, "Please wait...", true);
                        dialog.setContentPane(pane);
                       
                        dialog.setLocation(ODialerUIPreferences.getDataSourcePosition().x,
                                           ODialerUIPreferences.getDataSourcePosition().y);
                        dialog.pack();
                       
                        Thread finish =
                        new Thread(new Runnable()  {
                            Collection runners = mOpenRunners.values();
                            Thread openRunners[] = new Thread[runners.size()];
                            final Iterator itr = runners.iterator();
                            int i = 0;

                            public void run() {
                               
                                SwingUtilities.invokeLater(new Runnable() {
                                    public void run() {
                                        dialog.setVisible(true);    
                                    }
                                });                                  

                               
                                    while (itr.hasNext()) {
                                        System.out.println("supposedly...");
                                        final ODialerSwingGuiCampaignStatusDialog d =
                                            (ODialerSwingGuiCampaignStatusDialog)itr.next();
                                   
                                       
                                          openRunners[i] = (new Thread(new Runnable() {
                                              public void run() {
                                                  System.out.println("...stopping it");
                                                  d.fireODialerUIStopEvent();
                                              }                            
                                          }));
                                          openRunners[i].start();
                                          i++;
                                    }
                              
                                    for (i = 0; i < openRunners.length; i++) {
                                        try {
                                            openRunners[i].join();
                                        } catch (InterruptedException e) {}
                                    }
                            }
                        });
                        finish.start();
                        try {finish.join();} catch (InterruptedException e) {}
                       
                        dialog.setVisible(false);
0
 
dbrownell83Author Commented:
it doesnt block, but the dialog doesnt show either
0
 
dbrownell83Author Commented:
i raised the points since you've been so helpful.
but i would really like this to work
0
 
objectsCommented:
so what happens with the above?
0
 
dbrownell83Author Commented:
.
0
 
dbrownell83Author Commented:
the dialog doesnt become visible ever.  it does however call all the 'fireStopEvent's
0
 
objectsCommented:
>    try {finish.join();} catch (InterruptedException e) {}

Is the above code being cqalled on the EDT?
If so then you shouldn't be blocking it, that'll block any gui updates.
Instead hide your gui from the processing thread once it is done.

(SwingWorker handles a lot of this for you if you wanted to use it)
0
 
dbrownell83Author Commented:
hmm...
you mean like:
                                                .
                                                .
                                                .
                                                .
                                  for (i = 0; i < openRunners.length; i++) {
                                      try {
                                          openRunners[i].join();
                                      } catch (InterruptedException e) {}
                                  }

                                SwingUtilities.invokeLater(new Runnable() {
                                    public void run() {
                                        dialog.setVisible(false);    
                                    }
                                });  

                   }).start();
?

then the block finished immediately, and since this is in my exit code, exits...  hmm lemme put stacktraces in the exception blocks, cause i see what youre saying... that should work
0
 
dbrownell83Author Commented:
hmm.  i don't know man.  i'll let you go though.  thanks for the help.  i'll try the swingworker deal.
0
 
objectsCommented:
If you get stuck then let me know :)
0
 
dbrownell83Author Commented:
er i got stuck.
the swing worker is no good. haha.
i just placed everything up to and including the joins in the construct() method,
and placed the  SwingUtilities.invokeLater(new Runnable() {
                                    public void run() {
                                        dialog.setVisible(false);    
                                    }
                                });   in the finished() method.

it just closes, like in my comment 3 posts up.  
0
 
dbrownell83Author Commented:
and i tried without the SwingUtilities.invokelater......
and still no good
0
 
dbrownell83Author Commented:
ooh it seems to be joining before calling the stop method...
hold on...
0
 
dbrownell83Author Commented:
hmm i have to wait on the swing worker thread.  how do i do this?
0
 
dbrownell83Author Commented:
putting a notifyAll() at the end of finished()
and a wait() after I start it...
 doesnt work
0
 
objectsCommented:
What is it you need to wait for (and why)
0
 
dbrownell83Author Commented:
yes...  my problem is that i must join the swing worker thread
0
 
dbrownell83Author Commented:
well i'm trying to gracefully stop all the 'running campaign's, while this 'please wait' box is shown.

the problem is the SwingWorker starts, and then System.exit(0) is directly after it!
0
 
objectsCommented:
Why don't you just put the exit() call at the end of the thread?
0
 
dbrownell83Author Commented:
arg!  good night
0
 
dbrownell83Author Commented:
ok ill try
0
 
dbrownell83Author Commented:
ooh we're back to setVisible blocking...
but lemme put back on the SwingUtilitie invoke later thing...
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 32
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now