• Post Reply Bookmark Topic Watch Topic
  • New Topic

A problem with the behavior of JDialog.toFront()

 
Jon Swanson
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example application that creates a few JDialogs and then the intent is to use a menu pull down to pop a specific dialog to the front. It mostly works. The dialog I want in front of the others is in the front. However, the main frame ends up in the very back. I was hoping if the main frame was in the front of all my JDialogs, then popping one forward would leave the rest behind the main frame. Is the behavior I described expected or am I doing something wrong?





 
L Foster
Ranch Hand
Posts: 202
11
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not find this terribly surprising. However, I rarely use multiple frames of any kind, unless one is modal (holds focus until dismissed). I would tend to just let the user choose what they want.

That being said, nothing wrong with controlling things yourself. However, I tried experimenting with your code. It seems that (to my surprise) dialogs "flock together" wrt Z-order, and they will always be in front of that JFrame. This surprised me, because you did not set the JFrame as the owner of the JDialogs.

What did work was changing your PopDialogListener to below, along with changing the main JFrame to a JDialog, itself.



If you do that, you will get the desired effect, but it then complicates the whole notion of exit-on-close. I hope this helps.
 
Jon Swanson
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for looking at this. The JFrame is part of a large application. I don't think I can make it a JDilaog. Originally the request was for one, then several dialogs that remained available while working with the main program. Then the request for popping a specific dialog to the front once users got in the habit of starting lots of non-modal dialogs. I feel better knowing that the problem is not some obvious mistake on my part. Again thanks for the ideas to resolve the problem.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!