Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JDialog automatically close when another JDialog is open  RSS feed

 
kopparapu v kiran kumar
Ranch Hand
Posts: 32
Chrome Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In the swing application, JDialog box is used to display the list of persons. So that users can select the appropriate persons from the displayed list.

Now the problem is, this JDialog will be opened when we click on a button. There are many other buttons in the same JFrame. Each button will display different kind of information based on the input given in the textfield next to the button. When I click on a button JDialog opens, but when I click on the another button new JDialog opens, but the first one is still open(existing is not closed yet).

JDialog which is opened should be closed automatically when another button is opened. For example if I open a new JDialog box without closing existing open JDialog now both the Dialog boxes are opened together.

I request to provide few hints on this.

Here is the sample code :

 
K. Tsang
Bartender
Posts: 3620
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are designing your class? Do the various JDialogs know each other's existence?

If the components are in a central class then ideally it is possible to hide the "opened" dialogs before showing the new dialog.
 
kopparapu v kiran kumar
Ranch Hand
Posts: 32
Chrome Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tsang,

No, JDialog box does not know their existence. But partially I agree with your approach. If I'm not wrong then you mean to say that "have the references for all the Objects and make sure to close the already opened JDialog boxes".

Thanks for the quick reply. Apart from this will there be any other solution which Swing provides.

Regards,
Kiran
 
K. Tsang
Bartender
Posts: 3620
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the simplest is to add an extra parameter "alreadyOpenedDialog" in your class constructor that open dialogs.

The problem is once opened, where do you save this such that when a new dialog is opened it can get this reference.
 
kopparapu v kiran kumar
Ranch Hand
Posts: 32
Chrome Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you mentioned all the Dialog boxes are in the central class. I believe this will help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!