CardLayout - 如何更改组件名称
CardLayout - how to change name of component
有什么方法可以更改使用 CardLayout 添加到面板的面板的名称吗?我想使用 show
方法,而不必使用我在将面板添加到主面板时为其指定的名称。
JPanel panel = new JPanel();
add(panel, "0");
show(this, "0");
... // I change name of the panel to "1"
show(this, "1"); // now I can do this to show panel
// original cardPanel1 name is "card1"
CardLayout lay = (CardLayout)parentPanel.getLayout();
lay.removeLayoutComponent(cardPanel1);
lay.addLayoutComponent(cardPanel1, "card4");
// cardPanel1 can now be shown using "card4" name
有什么方法可以更改使用 CardLayout 添加到面板的面板的名称吗?我想使用 show
方法,而不必使用我在将面板添加到主面板时为其指定的名称。
JPanel panel = new JPanel();
add(panel, "0");
show(this, "0");
... // I change name of the panel to "1"
show(this, "1"); // now I can do this to show panel
// original cardPanel1 name is "card1"
CardLayout lay = (CardLayout)parentPanel.getLayout();
lay.removeLayoutComponent(cardPanel1);
lay.addLayoutComponent(cardPanel1, "card4");
// cardPanel1 can now be shown using "card4" name