是否有任何方法可以更改使用 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
关于java - CardLayout - 如何更改组件名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31884348/