Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

A button  close in JDialog

Thread view: 
shoa - 29 Jun 2005 03:37 GMT
Hello

I have a a JDialog (extends of JDialog class) object in that I have an
aPanel (extends of JPanel class). In this aPanel, I have button. When I
click this button, I want this dialog to close. Could you please tell me how
to do that.

I tried to use this function for the button:

this.getParent().dispose()     //obtain the parent (JDialog) then dispose it

but this function does not work

Thank you
S.Hoa
Andrew Thompson - 29 Jun 2005 10:17 GMT
> I have a a JDialog (extends of JDialog class) object in that I have an
> aPanel (extends of JPanel class). In this aPanel, I have button. When I
> click this button, I want this dialog to close.

setVisible(false)

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

shoa - 29 Jun 2005 13:18 GMT
If I use that function, only the panel inside the Dialog is hidden. The
Dialog is still visible.

> > I have a a JDialog (extends of JDialog class) object in that I have an
> > aPanel (extends of JPanel class). In this aPanel, I have button. When I
> > click this button, I want this dialog to close.
>
> setVisible(false)
Andrew Thompson - 29 Jun 2005 16:17 GMT
(Please refrain from top-posting - further comments in-line)

> "Andrew Thompson" <SeeMySites@www.invalid> wrote in message
>>
>>> ..When I
>>> click this button, I want this dialog to close.
>>
>> setVisible(false)

> If I use that function, only the panel inside the Dialog is hidden. The
> Dialog is still visible.

Well, duuh..  Try.

 theDialog.setVisible(false);

or.. (invoked from the right place)

 this.setVisible(false);

..which translates to

 setVisible(false);

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

shoa - 29 Jun 2005 23:32 GMT
Hello
As the button is inside a panel, this panel is inside a theDialog, I do not
know how to get the theDialog.setVisible(false).

I also tried
this.getParent().getParent().dispose() //this is the button
but it doesn't work

> Well, duuh..  Try.
>
[quoted text clipped - 7 lines]
>
>   setVisible(false);
Andrew Thompson - 30 Jun 2005 00:12 GMT
> As the button is inside a panel, this panel is inside a theDialog, I do not
> know how to get the theDialog.setVisible(false).

I could tell you, but you can probably figure it out
better by experimenting.

 // where is my mummy?
 Container c = (Container)this;
 while( c.getParent()!=null ) {
   c = c.getParent();
   System.out.println( "Container: " + c );
 }

> I also tried
> this.getParent().getParent().dispose() //this is the button
> but it doesn't work

Is it just lazy, perhaps?   ;-)

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

shoa - 30 Jun 2005 01:33 GMT
Thank you for your help

I have to use this to get it works. Too long !!!!

this.getParent().getParent().getParent().getParent().getParent().setVisible(
false)

I use your code and get

Container:
javax.swing.JPanel[,0,0,500x570,layout=java.awt.BorderLayout,alignmentX=null
,alignmentY=null,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
Container:
javax.swing.JPanel[null.contentPane,0,0,500x570,layout=javax.swing.JRootPane
$1,alignmentX=null,alignmentY=null,border=,flags=9,maximumSize=,minimumSize=
,preferredSize=]
Container:
javax.swing.JLayeredPane[null.layeredPane,0,0,500x570,alignmentX=null,alignm
entY=null,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,optimized
DrawingPossible=true]
Container:
javax.swing.JRootPane[,4,23,500x570,layout=javax.swing.JRootPane$RootLayout,
alignmentX=null,alignmentY=null,border=,flags=385,maximumSize=,minimumSize=,
preferredSize=]
Container:
super.ManagerWindow[dialog0,0,0,508x597,invalid,layout=java.awt.BorderLayout
,modeless,title=Manager Stocks
,defaultCloseOperation=DISPOSE_ON_CLOSE,rootPane=javax.swing.JRootPane[,4,23
,500x570,layout=javax.swing.JRootPane$RootLayout,alignmentX=null,alignmentY=
null,border=,flags=385,maximumSize=,minimumSize=,preferredSize=],rootPaneChe
ckingEnabled=true]
Container:
super.SuperApplication[frame0,0,0,350x150,invalid,layout=java.awt.BorderLayo
ut,title=,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JR
ootPane[,3,22,344x125,layout=javax.swing.JRootPane$RootLayout,alignmentX=nul
l,alignmentY=null,border=,flags=385,maximumSize=,minimumSize=,preferredSize=
],rootPaneCheckingEnabled=true]
Andrew Thompson - 30 Jun 2005 01:45 GMT
> Thank you for your help

You're welcome.

> I have to use this to get it works. Too long !!!!
>
> this.getParent().getParent().getParent().getParent().getParent().setVisible(
> false)

(chuckles)  That was just to help you *find* it, but is
very fragile.  There are probably better ways to get it,
like..

while ( c.getParent() ! instanceof TargetDialogClass ) {
 c = c.getParent();
}

..or storing a reference to the parent when constructing, or..

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

shoa - 30 Jun 2005 03:33 GMT
Thank you
I now understand more about  getParent() function

> > Thank you for your help
>
> You're welcome.
>
> > I have to use this to get it works. Too long !!!!

this.getParent().getParent().getParent().getParent().getParent().setVisible(
> > false)
>
[quoted text clipped - 7 lines]
>
> ..or storing a reference to the parent when constructing, or..
Vova Reznik - 30 Jun 2005 14:54 GMT
> Thank you
> I now understand more about  getParent() function
[quoted text clipped - 18 lines]
>>
>>..or storing a reference to the parent when constructing, or..

It is not about understanding *getParent()* method.
It is about understanding who is the PARENT. :)
Thomas Weidenfeller - 30 Jun 2005 08:40 GMT
> (chuckles)  That was just to help you *find* it, but is
> very fragile.  There are probably better ways to get it,
[quoted text clipped - 3 lines]
>   c = c.getParent();
> }

SwingUtilities.getWindowAncestor()

> ..or storing a reference to the parent when constructing, or..

Or have some central repository where all your top-level windows
register and de-register.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Andrew Thompson - 30 Jun 2005 09:51 GMT
>> while ( c.getParent() ! instanceof TargetDialogClass ) {
>>   c = c.getParent();
>> }
>
> SwingUtilities.getWindowAncestor()

..(checks subject line) Good point.  I had
completely lost that this was a *Swing* GUI
matter and was thinking 'valid back to 1.1!'
( same old story ;)

As an aside, do you know if that method has
been available since the introduction of Swing?  
The javadocs are a bit vague on some of the
'@since' tags..

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Thomas Weidenfeller - 30 Jun 2005 12:17 GMT
> As an aside, do you know if that method has
> been available since the introduction of Swing?  

AFAIK it was added for 1.3

> The javadocs are a bit vague on some of the
> '@since' tags..

That's an understatement. Correct @since tags seem to be completely out
of the scope of Sun's QA.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Vova Reznik - 30 Jun 2005 15:00 GMT
>> (chuckles)  That was just to help you *find* it, but is
>> very fragile.  There are probably better ways to get it, like..
[quoted text clipped - 11 lines]
>
> /Thomas

SwingUtilities.getWindowAncestor(Component)
or
jComponent.getTopLevelAncestor()
Vova Reznik - 30 Jun 2005 14:48 GMT
> this.getParent().getParent().dispose() //this is the button
> but it doesn't work

It will not work, because parent of content pane is not JDialog.
You should not be able to compile.
Vova Reznik - 29 Jun 2005 14:37 GMT
> Hello
>
[quoted text clipped - 11 lines]
> Thank you
> S.Hoa

What is *this*?
If this is button - parent is JPanel
If this is JPanel - parent is Contanier (JDialog content pane)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.