• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about JDialog?

 
lakmal padmakumara
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUIs forum, where we usually discuss such questions.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And actually moving


You could override the setVisible(boolean) method to clear the GUI first if you show it:
 
mark goking
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 10974
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic