1

This is the scenario:

  • add windowOpened() handler to new instance of JDialog
  • show dialog for the first time using jdialog.setVisible(true)
  • as expected: windowOpened() handler triggered
  • jdialog.setVisible(false)
  • jdialog.setVisible(true)
  • expected, but not happened: windowOpened() handler triggered

How do I handle situation when my modal dialog appeared on the screen whenever it was first time or subsequent times I called setVisible(true) ?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Sergey Karpushin
  • 874
  • 1
  • 10
  • 33
  • possible duplicate of [JPanel which one of Listeners is proper for visibility is changed](http://stackoverflow.com/questions/10880326/jpanel-which-one-of-listeners-is-proper-for-visibility-is-changed) – Duncan Jones Apr 25 '13 at 11:36
  • Well... reference is useful, thank you. But it's not a duplicate, since my question is exactly about JDialog, but not anything which a subclass of JComponent – Sergey Karpushin Apr 25 '13 at 12:41
  • I considered it a duplicate because your question is a subset of the one I referenced. Either way, glad you have an answer. – Duncan Jones Apr 25 '13 at 12:45

1 Answers1

3

How do I handle situation when my modal dialog appeared on the screen whenever it was first time or subsequent times I called setVisible(true) ?

  • have to use ComponentListener, and to override methods componentHidden() and componentShown()

  • JComponent must returns true from isDisplayable()

  • more here

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319