I'm working on a program that traverses a list of objects every pass through. When an object's "time" (i.e. number of passes) is up, it brings up a JDialog to request its next task. The problem is how to deal with multiple objects making this request on a single pass.
If I make the JDialog modal, each object makes its request in turn, which is what I want; but the main program window is unavailable, which I do not want.
If the JDialog is not modal, multiple instances appear, one for each pass, which I do not want; or, if I set it up as a singleton, only one instance appears but only the last object int the list to make the request gets to use it.
Is there a way I can pop up the dialog, leave other windows available to the user, and have the other objects wait their turn to use the dialog?
As noted in comments, the problem can be addressed by altering the modality of the parent
Window
. On the downside, the "behavior is implementation-dependent."As an alternative, consider traversing the objects in the background thread of a
SwingWorker
and adding new candidates to a suitable component, e.g.JList
,JTable
, orJTabbedPane
. Selecting an element form the component would bring up a conventional modal dialog, removing the element on completion. A related example is shown here. Each of the suggested components can be labeled with an icon representing its status.