different ways of closing a jDialog

Im having a jdialog named SUBDIALOG' which will be invoked by an anotther jdialog named 'PARENTDIALOG'.

to close the SUBDIALOG im using the method "dispose()" .

When i reopen the SUBDIALOG a huge run time exception is thrown , which is at the bottom of this mail .

I came to know that its a bug in JAVA which occurs while closing a frame .

So please suggest me the different ways of closing a jDialog .

In the SUBDIALOG ihave used a jTable which is editable .

Whenever i invoke the dialog(containing the Jtable) for the first time , everything will go fine .

After closing the dialog , if we re invoke it, i am unable to edit the Jtable . The following error is being thrown .

java.lang.NullPointerException

at sun.awt.windows.WInputMethod.dispatchEvent(WInputMethod.java:253)

at sun.awt.im.InputContext.dispatchEvent(InputContext.java:238)

at sun.awt.im.InputMethodContext.dispatchEvent(InputMethodContext.java:180)

at java.awt.Component.dispatchEventImpl(Component.java:3565)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:3323)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3180)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

[2174 byte] By [rajeshreddyka] at [2007-11-27 7:03:06]
# 1
Instead of using dispose(), try using setVisible(false). This is atleast has never given me an exeption before
icewalker2ga at 2007-7-12 18:54:15 > top of Java-index,Desktop,Core GUI APIs...
# 2
I have used both , SETVISIBLE(false) and dispose() .Even i tried with SETVISIBLE(false) alone. But it is still visible
rajeshreddyka at 2007-7-12 18:54:15 > top of Java-index,Desktop,Core GUI APIs...
# 3

> I have used both , SETVISIBLE(false) and dispose(). Even i tried with SETVISIBLE(false) alone. But it is still visible

Well you have a coding problem and since we can't see your code we can't help.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

camickra at 2007-7-12 18:54:15 > top of Java-index,Desktop,Core GUI APIs...
# 4

When you use the dispose method on your JDialog, it essentially releases the dialog from memory. So if you try to show the window again, that will throw the exception. I assume that you just want to hide the sub window, and not dispose of it.

Let's say your dialog's class name is MyCoolDialog. Here's the command to close the window (use this inside a JButton's actionPerformed event):

MyCoolDialog.this.setVisible(false);

Also, don't forget to set the JDialog's default close operation sometime during the dialog's initialization:

MyCoolDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

If you do want to dispose of the window (and not hide it), then remember to create a new reference to the window, set the default close operation to DISPOSE_ON_CLOSE, use the setVisible example I gave you above for the actionPerformed event, and that should bypass your null pointer exception.

Miscellaneous edits to this post. I'm had a few ID-10-T exceptions this morning...lol.

Message was edited by:

HTPC2Good4U

HTPC2Good4Ua at 2007-7-12 18:54:15 > top of Java-index,Desktop,Core GUI APIs...
# 5
As you suggested i used the following code inside the Closebutton action performed event setVisible(false);But even after clicking the close button , the jdialog where the close button is present is not getting invisible or closed.Kindly suggest me
rajeshreddyka at 2007-7-12 18:54:15 > top of Java-index,Desktop,Core GUI APIs...
# 6
You've already been given suggestions. Your code is wrong. There is nothing tricky about this.You've been asked to post a SSCCE. If you don't, then I guess you don't want any more help.
camickra at 2007-7-12 18:54:15 > top of Java-index,Desktop,Core GUI APIs...