-1

I have a JFrame that contains dynamic content and

my_frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

The frame is show only when the user press a JButton and my_frame class contains only a constructor (for fist time invocation) and a refresh method for refreshing its content. Now i would that when the JFrame become visibile again, my_frame intercept the event and call automatically the refresh method. How can i do it?

giozh
  • 9,868
  • 30
  • 102
  • 183
  • 2
    Take a look at [How to write Window Listeners](http://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html) and [`WindowListener`](http://docs.oracle.com/javase/7/docs/api/java/awt/event/WindowListener.html) for some ideas – MadProgrammer Aug 06 '13 at 09:23
  • aside `Now i would that when the JFrame become visibile again` != `WindowListener` my view – mKorbel Aug 06 '13 at 09:42

1 Answers1

3

Now i would that when the JFrame become visibile again, my_frame intercept the event and call automatically the refresh method. How can i do it?

  • good concept, very good idea to re_use one Top-Level Container

  • I'd suggest to use JDialog(parent) instead of JFrame

  • you can to call my_frame.setVisible(true), by assuming that my_frame is declared and initialized as variable

  • or Window[] wins = Window.getWindows(); returns array of Top-Level Container, inside loop in this array you can to test if (wins[i] instanceof JFrame) {, then call wins[i].setVisible(true);

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • thanks. I've found that for do what i need, just add a ComponentListener and use componentShown method of ComponentAdapter for handle the event. – giozh Aug 06 '13 at 10:09
  • [see more](http://stackoverflow.com/questions/10880326/jpanel-which-one-of-listeners-is-proper-for-visibility-is-changed) – mKorbel Aug 06 '13 at 11:41