CardLayout的父容器/面板 [英] Parent container/panel for a CardLayout
本文介绍了CardLayout的父容器/面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为CardLayout
中的任何面板获取容器"面板.
How I can get the 'container' panel for any panel in CardLayout
.
也就是说,如果面板是卡 在另一个容器"面板中,然后如何从卡中获取对此容器"面板的引用?
That is, if a panel is a card in another 'container' panel, then how to get reference to this 'container' panel, from the card?
这就是我在做什么:-
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);
}
...
推荐答案
You can use the method getParent that is provided by the Component
superclass. For your panel that is a card, simply call panel.getParent()
and it will give you the containing (parent) panel.
这篇关于CardLayout的父容器/面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文