문제

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?
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top