CARDLAYOUT中判断当前显示的是哪个部件

csdn论坛里搜了半天居然都是要写什么监听的, 麻烦的要死, 其实简单的很啊

//拿到panel和cardlayout
JPanel cardPanel = (JPanel)map.get("cardNewsPanel");
CardLayout cardLayout = (CardLayout) (cardPanel.getLayout());

//都在容器里呢, 看一下visible就知道哪个被显示了
for(int i=0;i            java.awt.Component c = cardPanel.getComponent(i);
            System.out.println("name:"+c.getName()+" visable"+c.isVisible());
 }


你可能感兴趣的:(Java最爱)