Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Close JDialog without hide

 
dushantha Rathnayake
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have an application. So I use JFrame to my main GUI. And JDialog's to other GUI's. But the problem is, after I call to a sub class(they are with JDialog) and do work and close. Then again I want to call previous sub class, but there are previous data. I did set the DefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE). I can't set the DefaultCloseOperation as EXIT_ON_CLOSE. what I want to do now. I want to close the Dialog.No need to hide it.please help me.

Thank you!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Then again I want to call previous sub class, but there are previous data.

create a new instance of the sub-class each time
e.g. new MyDialog(parent);
 
dushantha Rathnayake
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:

create a new instance of the sub-class each time
e.g. new MyDialog(parent);


Hi,

Actually I don't know how many times the user wants to open that window and do their work. Think, that window use to print a document. so first time there are no any errors. But after close that window and again open, there are previous data and user wants to clear that. But in this case my application is not a better program. Actually I don't know, what I want to do now. Please help me.

Thank you!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post the code:
1) when the dialog opens the first time
2) when the dialog opens other times
 
dushantha Rathnayake
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Main GUI


printing GUI


If you want the data base, I can send it to your email.Please tell me that if you want or not.

Thank you!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your problem would be the 'static' dialogs

here's a simple demo showing what happens


run the code, click 'show dialog', enter something into the dialog's textfield, click 'X' to close,
click 'show dialog' again and your entered text will remain (which should be the problem you describe).

now remove the word static from
static JDialog d = new JDialog();
recompile and repeat above steps, 2nd showing of dialog should have a cleared textfield (what you want)
 
dushantha Rathnayake
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,

Sorry for the late. Actually you are correct but, I use this static dialogs for another activity. It is, after open a dialog i want to minimize my main application but in this case i have to identify which dialogs are opened and I have to hide them (Actually this also my fault. I didn't use JInternalFrames. But the problem is now the project is close to delivery part) .that because I use this static Dialogs. If I remove this static part how can I hide them?

Thank you!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> If I remove this static part how can I hide them?

I don't know what you really mean by 'hide'

obviously, just using setVisible(false) will hide them,
but then, on setVisible(true), they'd reappear with any data still in the text components.

perhaps you should be using
dialog.dispose();
and add it at the end of a button's actionListener

alternatively you could create a 'reset' method, which clears all text from text components
and call this method from a windowListener's windowActivated()
 
dushantha Rathnayake
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,

Actually you are correct. Before I used a external class and call it. Now I insert that code inside into main class.now it is work properly.Thank you very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic