Assume we have the following Swing application:
final JFrame frame = new JFrame();
final JPanel outer = new JPanel();
frame.add(outer);
JCompon
Thanks aioobe for your answer - I got here via Google, looking for the same thing. :-) It's worth noting that Component.isShowing()
does the same job as your amIVisible()
though, so a revised code snippet (including a check on the nature of the HierarchyEvent
) might be:
class SomeSpecialComponent extends JComponent implements HierarchyListener {
public void addNotify() {
super.addNotify();
addHierarchyListener(this);
}
public void removeNotify() {
removeHierarchyListener(this);
super.removeNotify();
}
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0)
System.out.println("Am I visible? " + isShowing());
}
}