Article View: borland.public.jbuilder.java.swing
Article #1487Re: How to get values from a popup JDialog
From: Paul Furbacher
Date: Thu, 11 Dec 2003 18:37
Date: Thu, 11 Dec 2003 18:37
61 lines
2749 bytes
2749 bytes
Roel wrote:
> Lets say I have a popup JDialog and it has a JTextField.
> How do I get the value of the JTextField back into my main application
> to use it? E.g username and password.
Add properties, with getter/setter methods,
to the dialog object. Very straightforward.
public class MyDialog extends JDialog {
...
private boolean wasCanceled = true;
// I omit member fields, constructor
// for the sake of brevity ...
public String getUserName() {
return userNameTF.getText();
}
public void setUserName(String name) {
userNameTF.setText(name);
}
// Do the same for the password.
...
// Also, keep a record of which button the
// user pressed. Add actionListeners to the
// OK and Cancel buttons and set the "wasCanceled"
// field.
public boolean wasCanceled() { return wasCanceled; }
}
When calling your dialog:
MyDialog d = new MyDialog(...);
d.setModal(true);
d.setUserName("Roel");
d.show();
if ( ! d.wasCanceled() ) {
String uname = d.getUserName();
String pw = d.getPassword();
// do what you have to do with
// this info ...
}
d.dispose();
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Technical Details
Message-ID:
<3fd8b96f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fd84325$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,336ccfd53d4a7a21 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2003-12-11 10:39:38 PST Date: Thu, 11 Dec 2003 13:37:35 -0500 From: Paul Furbacher <pfurbacher@mac.com> User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5) Gecko/20031013 Thunderbird/0.3 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: How to get values from a popup JDialog References: <3fd84325$1@newsgroups.borland.com> In-Reply-To: <3fd84325$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 68.39.103.120 Message-ID: <3fd8b96f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1071167855 68.39.103.120 (11 Dec 2003 10:37:35 -0700) Lines: 62 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail