• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JFrame as a Dialog

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Marshal
Posts: 79475
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic