Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can�t we create a modal dialog using JPanel?  RSS feed

 
Venu Gopal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you see the JDialog constructor API, these constructors will allow either a Frame or a Dialog as owners (owner from which the dialog is displayed --- See the constructors for more info about the use of owner.).
But in my case, I have to show/popup this JDialog from a JPanel.
I want a modal dialog (don�t want a non-modal dialog) and I don�t have either a Frame or a Dialog as owner (but only have JPanel).
how to achieve a modal dialog?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JPanel has a parent frame. It has to. So just use that.
 
Venu Gopal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"public class JPanel extends JComponent"
may i know which parent frame you are talking abuot!!??
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I bet he is referring to the container returned by JComponent.getTopLevelAncestor.
I have found it looking at the API.
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just call getParent() recursively til you get an instanceof a Frame or Dialog. once you get one, use that.
brian
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, um do the whole ancestor thing.
The dialog just wants to know what window/frame/whatever is it's parent so if the parent is closed, the JVM can take care of destroying all of it's child windows too.
Heck, you could probably just pass a null value to the constructor and everything will be hunky-dory if it's modal and you don't have other threads floating around out there to complicate things for you.
 
Tim Troy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From 2003-11-24 The Java Specialists' Newsletter [Issue 081] - Catching Exceptions in GUI Code
Author: Dr. Heinz M. Kabutz
Java Specialists
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!