• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 22683
128
Eclipse IDE Spring VI Editor 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: 76447
366
  • 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.
 
Everybody! Do the Funky Monkey! Like this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic