Question

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?
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top