Search code examples
javaswingjdialogwindowlistener

How to handle JDialog opened after setVisible(false)?


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) ?


Solution

  • 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