• Post Reply Bookmark Topic Watch Topic
  • New Topic

MODAL JFRAME  RSS feed

 
NILESH PATEL
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello good wishers,
Does someone know how can we make a JFrame( or its subclass) a modal. For those who do not know what modal is: Modal means only dialog/frame can be worked with while it is active. To work with other windows for same application running, current window must be closed.
What I tried to do is, I created a class extending javax.swing.JFrame, after which in the main method, I created JDialog passing new JDialog(this, true). this means the frmae to be modaled and true means make this frame modal.
But executing this program will cause just a small frame with nothing in it, whereas I would expect all the components, as I would expect with frame.setVisible(true).
I don't know why and how to resolve this. Please let me know ASAP.
Thanks all in advance.
Nilesh
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make a frame modal to the application by using a JDialog instead of JFrame. However, you can't make a frame model to the computer using just java... you'd have to use JNI or something to evoke system code...

It sounds like you got messed up using the JDialog... the way to fix your code would be to move all the components on your frame onto the dialog you create... in the JDialog( Frame, boolean ) constructor, the Frame indicates the parent of the dialog you are creating, and whether the new dialog itself is modal or not...

-Nate
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!