Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > A button close in JDialog

Reply
Thread Tools

A button close in JDialog

 
 
shoa
Guest
Posts: n/a
 
      06-29-2005
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



 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      06-29-2005
On Wed, 29 Jun 2005 14:39:30 +1200, shoa wrote:

> 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
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
 
Reply With Quote
 
 
 
 
shoa
Guest
Posts: n/a
 
      06-29-2005
If I use that function, only the panel inside the Dialog is hidden. The
Dialog is still visible.

"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:1nauxpvkf9gdu.v2u7rmlexaia$(E-Mail Removed)...
> On Wed, 29 Jun 2005 14:39:30 +1200, shoa wrote:
>
> > 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
> 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



 
Reply With Quote
 
Vova Reznik
Guest
Posts: n/a
 
      06-29-2005
shoa wrote:
> 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
>
>
>

What is *this*?
If this is button - parent is JPanel
If this is JPanel - parent is Contanier (JDialog content pane)
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-29-2005
On Thu, 30 Jun 2005 00:18:29 +1200, shoa wrote:

(Please refrain from top-posting - further comments in-line)

> "Andrew Thompson" <(E-Mail Removed)> wrote in message
>> On Wed, 29 Jun 2005 14:39:30 +1200, shoa wrote:
>>
>>> ..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);

--
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
 
Reply With Quote
 
shoa
Guest
Posts: n/a
 
      06-29-2005
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.
>
> theDialog.setVisible(false);
>
> or.. (invoked from the right place)
>
> this.setVisible(false);
>
> ..which translates to
>
> setVisible(false);
>
> --
> 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



 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-29-2005
On Thu, 30 Jun 2005 10:33:56 +1200, shoa wrote:

> 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?

--
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
 
Reply With Quote
 
shoa
Guest
Posts: n/a
 
      06-30-2005
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,alignmen tX=null
,alignmentY=null,border=,flags=9,maximumSize=,mini mumSize=,preferredSize=]
Container:
javax.swing.JPanel[null.contentPane,0,0,500x570,layout=javax.swing.JR ootPane
$1,alignmentX=null,alignmentY=null,border=,flags=9 ,maximumSize=,minimumSize=
,preferredSize=]
Container:
javax.swing.JLayeredPane[null.layeredPane,0,0,500x570,alignmentX=null,align m
entY=null,border=,flags=0,maximumSize=,minimumSize =,preferredSize=,optimized
DrawingPossible=true]
Container:
javax.swing.JRootPane[,4,23,500x570,layout=javax.swing.JRootPane$RootLay out,
alignmentX=null,alignmentY=null,border=,flags=385, maximumSize=,minimumSize=,
preferredSize=]
Container:
super.ManagerWindow[dialog0,0,0,508x597,invalid,layout=java.awt.Border Layout
,modeless,title=Manager Stocks
,defaultCloseOperation=DISPOSE_ON_CLOSE,rootPane=j avax.swing.JRootPane[,4,23
,500x570,layout=javax.swing.JRootPane$RootLayout,a lignmentX=null,alignmentY=
null,border=,flags=385,maximumSize=,minimumSize=,p referredSize=],rootPaneChe
ckingEnabled=true]
Container:
super.SuperApplication[frame0,0,0,350x150,invalid,layout=java.awt.BorderL ayo
ut,title=,normal,defaultCloseOperation=HIDE_ON_CLO SE,rootPane=javax.swing.JR
ootPane[,3,22,344x125,layout=javax.swing.JRootPane$RootLay out,alignmentX=nul
l,alignmentY=null,border=,flags=385,maximumSize=,m inimumSize=,preferredSize=
],rootPaneCheckingEnabled=true]


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-30-2005
On Thu, 30 Jun 2005 12:34:14 +1200, shoa wrote:

> 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..

--
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
 
Reply With Quote
 
shoa
Guest
Posts: n/a
 
      06-30-2005
Thank you
I now understand more about getParent() function

"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:1owpm1cv94obc$.qxw3qw22o90e$(E-Mail Removed).. .
> On Thu, 30 Jun 2005 12:34:14 +1200, shoa wrote:
>
> > 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..
>
> --
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
JDialog from Icon close emekadavid Java 1 06-06-2008 03:26 PM
Gmail: the Back button (vs. Close button)...onBeforeUnload? allan.young@gmail.com Javascript 5 03-22-2007 09:50 PM
a solution to overcome the absence of maximize/minimize button in a JDialog Mariano Java 0 12-02-2006 10:03 AM
Re: JDialog in taskbar under Linux Alexandr Molochnikov Java 0 07-31-2003 12:24 AM



Advertisments