JDialog and returning value

M

mdema@diesel

Hi everybody
I'd like a JDialog to return a value (a string, in this case) when is
closed.
Is this possible?
My situation is like this:
I have a main frame, then the Dialog is opened, some datas are put by
the user in a text area and then the dialog is closed, but I need to
access those datas.
Thank you very much!
 
S

Stefan Ram

mdema@diesel said:
I'd like a JDialog to return a value (a string, in this case) when is
closed.
Is this possible?

You can implement an extension of this class with a method:

public java.lang.string close();

But this would be misleading to others, since usually a close
operation (as in java.io.Closeable) does not return a value.

Another possibility:

Make the object of your custom dialog class to be a component
with an external model. Then, have the controller of the
custom dialog component write the input read into the model.
Then, even after the component has been closed, the data read
will still be in the model.
 
K

Knute Johnson

mdema@diesel said:
Hi everybody
I'd like a JDialog to return a value (a string, in this case) when is
closed.
Is this possible?
My situation is like this:
I have a main frame, then the Dialog is opened, some datas are put by
the user in a text area and then the dialog is closed, but I need to
access those datas.
Thank you very much!

See the docs; JOptionPane.showInputDialog() it does exactly what you want.

If you need something more complicated than a single String then just
get the data from the components in the dialog after it is closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top