• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can�t we create a modal dialog using JPanel?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic