我如何获得任何面板的“容器”面板CardLayout
.
也就是说,如果面板是一张卡片
在另一个“容器”面板中,那么如何从卡中获取对此“容器”面板的引用?
这就是我正在做的:-
public class LogInPanel extends javax.swing.JPanel implements ActionListener{
/**
* Creates new form Panel2
*/
private JPanel parentPanel;
private CardLayout c1=null;
public LogInPanel() {
initComponents();
//c1=new CardLayout();
parentPanel=(JPanel)(SwingUtilities.getAncestorOfClass(this.getClass(), this));
c1=(CardLayout)(parentPanel.getLayout());
submitLogin.addActionListener(this);
}
...
你可以使用该方法获取父级这是由提供的Component
超类。对于您的面板是一张卡,只需调用panel.getParent()
它会给你包含(父)面板。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)