This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How instantiate a JDialog form from a JPanel  RSS feed

 
D. Formenton
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear sirs,

I have a JDialog with a JButton and I would like that when I click the JButton will instantiate a new JDialog form e.g.:

private void btnAddSessioneActionPerformed(java.awt.event.ActionEvent evt){
FrmFindSessioni findSessioni = new FrmFindSessioni(this, false);

but I get an error because does not exist a constructor of JDialog for a JPanel parent (only for JFrame and JDialog).

How I can solve this situation?

Thank you

Domenico
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sort of question is usually discussed in our Swing forum. Moving.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of 'this', use
SwingUtilities.getAncestorOfClass(..)
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
instead of 'this', use
SwingUtilities.getAncestorOfClass(..)


This might be a problem in case of nested panels.
I would suggest JComponent#getTopLevelAncestor()
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> This might be a problem in case of nested panels.

works fine for me
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:instead of 'this', use
SwingUtilities.getAncestorOfClass(..)

I've usually used SwingUtilities.getWindowAncestor(...). It likely does the same thing, but requires one less parameter. I know, big whoop!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!