1

I am using Java CardLayout to switch between cards and JPanel. When activity starts in android I can use onLoad, or similar to check if the activity is now open. What is the equivalent to this in swing? How can I know if the JPanel (Card) is now in front?

public class FirstScreen extends JPanel 
{
//am I visible now?
}
mKorbel
  • 109,107
  • 18
  • 130
  • 305
Dim
  • 4,084
  • 12
  • 74
  • 131
  • 1
    A Panel should go inside a Frame. You mean being visible into the Frame or the frame itself to be visible in the OS desktop? – Aritz Aug 06 '13 at 12:43
  • The JPanel is inside frame in other class, when I open it I use show function. When the FirstScreen is shown I need to know about this in itself. – Dim Aug 06 '13 at 12:47

1 Answers1

2

Implement windowActivated() in a WindowListener or WindowAdapter, as shown in How to Write Window Listeners and this example. See also How to Write a Component Listener.

Addendum: To receive notification that a particular card was selected, use a PropertyChangeEvent, as shown here, or an AncestorEvent, as shown here.

Community
  • 1
  • 1
trashgod
  • 200,320
  • 28
  • 229
  • 974
  • @mKorbel: good idea; there's an `AncestorListener` example [here](http://stackoverflow.com/a/17993449/230513). – trashgod Aug 06 '13 at 13:45