如何在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);
}
...发布于 2013-02-02 13:49:03
您可以使用Component超类提供的方法getParent。对于您的卡片面板,只需调用panel.getParent(),它将为您提供包含(父)面板。
https://stackoverflow.com/questions/14659033
复制相似问题