• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin


Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

    Bookmark Topic Watch Topic
  • New Topic