Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
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?
 
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!!??
 
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.
 
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
 
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.
 
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!