How do I identify whether a JDialog component is already opened or not, thus, it would avoid the same JDialog to be opened twice at the same application instance?
One solution I had in mind was to verify whether an object is already a JDialog instance (dialogObj instanceof JDialog), if so, I just call the method responsible for its construction / exhibition, if not, I just create a new JDialog instance (fill free to correct me if I’m delusional).
Let’s suppose I’ve created a JDialog containing one (1) JPanel, one (1) JTextField, one (1) JButton and the element that holds the event who will “display” the JDialog every time is a JMenuItem -> JPopUpMenu -> TrayIcon (System Tray icon).
I’ve almost discovered a way to solve it (as shown at the second paragraph), however, when I open it again through the System Tray, everything what I’ve typed before I’ve “disposed” the dialog box appears again, not to mention the others elements status that remains the same (JButton enabled etc – its another story).
Does anyone here have a clue how to solve it (of course it does)?
To solve both tasks as
You can simply use a modal JDialog as
…this won’t let user to init another JDialog example 🙂
Good luck