Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFrame as a Dialog

 
singh sagar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i am using 2 JFrames, one JFrame( say Frame 'A') calling other ( Say Frame 'B')as a dialog Frame, but the problem i am facing is that when both the frames are visible then i can also click on Frame A, instead i want that when both of them are visible than i can only operate on Frame B(Just As FRAME B IS A DIALOG), and clicking on Frame A will also Give Focus to Frame B.

Please Help.
Thanks
Sagar
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution is to avoid creating classes that create JFrames or JDialogs if possible, but instead have your GUI classes produce JPanels. This way you gives you a lot more flexibility and allows you to place your GUIs (JPanels) inside of either of the two root containers, a JApplet, or any other containers as you desire.
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first question is, if you want B to act as a dialog, then why not make it a JDialog instead?

Also, Pete's solution gives you much more flexibility.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One other fix / kludge would be to extract your JFrame's contentPane and put it in a newly created modal JDialog, but this is not very elegant (in my mind).
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See whether you can set the Frame with a modal property. See whether you can write a MouseListener which transfers focus on clicking.

But why on earth don't you use Dialogs in the first place? Frames are designed to be Frames, and Dialogs are designed to be dialogs.
 
singh sagar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All for replying


One other fix / kludge would be to extract your JFrame's contentPane and put it in a newly created modal JDialog, but this is not very elegant (in my mind).


Pete can you please elaborate what you want to say.

My first question is, if you want B to act as a dialog, then why not make it a JDialog instead?


Rob its like i have two different application and now i am communicating between them, so i cant make the Frame B as Dialog.

See whether you can set the Frame with a modal property. See whether you can write a MouseListener which transfers focus on clicking


Campbell , no Frame do not have Modal property, and writing a MouseListner way may work, but how to transfer focus

One Way i have found is to setting the Frame A as setEnabled(false); and when frame B closes setting the Frame A as setEnabled(true); but in this case Frame A is not maximised when frame B closes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic