Another instance of same window.

Another instance of same window.

Post by kalpes » Tue, 25 Apr 2006 21:44:19


i have an application in which after selecting an item from JMenuBar
another window is opened.Again selecting the same option the window is
opened once again.
I want that once a particular window is opened another instance of same
window should not open.
 
 
 

Another instance of same window.

Post by kalpes » Tue, 25 Apr 2006 21:44:25

i have an application in which after selecting an item from JMenuBar
another window is opened.Again selecting the same option the window is
opened once again.
I want that once a particular window is opened another instance of same
window should not open.

 
 
 

Another instance of same window.

Post by tar » Wed, 26 Apr 2006 01:04:14

"kalpesh" < XXXX@XXXXX.COM > writes:


Have the menu action that creates the window disable the menu item.

You will also want to have the close action for that window enable the
menu item for creating it again.

--
Thomas A. Russ, USC/Information Sciences Institute
 
 
 

Another instance of same window.

Post by Ian Wilso » Wed, 26 Apr 2006 01:04:17


I'm new to Java but a few (possibly foolish) ideas occur to me:

1) Make the window modal (using JOptionPane instead of e.g. JFrame).

or
2) Keep track of window state (open, not) in a static boolean tested &
set in the constructor. Though this would need care to eliminate
possible race conditions.

or
3) instantiate the window when the app starts up, thenceforward just use
its setVisible(true) rather than instantiating it. use setVisible(false)
rather than closing it.

I've used option 1 but am interested in finding out what other ways
there are of structuring an application. What approach are you using?
 
 
 

Another instance of same window.

Post by Monique Y. » Wed, 26 Apr 2006 03:36:35

On 2006-04-24, Ian Wilson penned:

You could also instantiate the window the first time a user tries to
open it; thereafter just do setVisible() ...

--
monique

Help us help you:
http://www.yqcomputer.com/ ~esr/faqs/smart-questions.html
 
 
 

Another instance of same window.

Post by Murdo » Wed, 26 Apr 2006 06:27:28


Whenever the menu item is selected for the first time, add an entry for the instance into a
List/Map with a mapping of:

<UniqueMenuItemID>,<WindowInstance>

The next time the menu item is selected, look for the entry in the list. If it is there, and the
WindowInstance is still valid, then you can apply focus to the original window. Otherwise, you will
want to re-create the window, and update the list.

--