wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JFrame as a Dialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame as a Dialog" Watch "JFrame as a Dialog" New topic
Author

JFrame as a Dialog

singh sagar
Ranch Hand

Joined: Sep 23, 2007
Posts: 30
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Oct 27, 2005
Posts: 19679
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Oct 13, 2005
Posts: 38478
    
  23
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

Joined: Sep 23, 2007
Posts: 30
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.
 
 
subject: JFrame as a Dialog