aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Question about JDialog? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Question about JDialog?" Watch "Question about JDialog?" New topic
Author

Question about JDialog?

lakmal padmakumara
Ranch Hand

Joined: Aug 08, 2009
Posts: 47
I'm developing a small application in Netbeans.And It has a Jdialog which takes some user inputs.
After taking them I hide that dialog box saying setVisible(false).

Then when i want to get some new user inputs I called it using setVisible(true).Problem is in the second time those user input fields contains the data I entered in the first time .

But what i want is a fresh copy of that dialog ! Do I have to call setText(null) method manually for each and every field or is there a way to get a fresh copy of that Dialog?

Please help !!


[Bsc in Computer Science and Engineering] [SCJP 80%][BCS certificate level]
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
lakmal padmakumara wrote: Do I have to call setText(null) method manually for each and every field or is there a way to get a fresh copy of that Dialog?


You could create a new instance...


OCJP 6 (93%)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39416
    
  28
Moving to our GUIs forum, where we usually discuss such questions.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

And actually moving


You could override the setVisible(boolean) method to clear the GUI first if you show it:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
there is nothing wrong with calling setText("") or setText(null) manually;

you can create a custom method where your jdialog.setvisible(true); and textfield.setText("") are called


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

If the dialog is as simple as you imply, just dispose of it when you are done and create a new instance when you need it.


GenRocket - Experts at Building Test Data
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Gregg Bolinger wrote:If the dialog is as simple as you imply, just dispose of it when you are done and create a new instance when you need it.


I am with Gregg here.
You will find this easier, especially if you are using the JOptionPane.showXXX methods to create the dialog. It can still be done with JOptionPane but that would mean unnecessary complications and more lines of code which in my opinion is not worth the effort. Easiest would be provide a new instance of your input field, which would be 1 line of code.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about JDialog?