我想在鼠标单击事件时从 ContentPanel 中删除所有元素并添加新元素。它与removeAll()方法一起工作正常,这会删除所有现有组件。但是当我想添加一个新组件时,它没有添加。
最佳答案
也许像这样我省略了点击处理程序,但你应该从中得到想法。
private ContentPanel contentPanel;
public SwapScreen() {
contentPanel = new ContentPanel();
add(contentPanel);
}
public void swap1() {
/*This should be split into a separate
method and called only once to avoid recreating them.*/
field1 = new TextField<String>();
contentPanel.add(field1);
field2 = new TextField<String>();
contentPanel.add(field2);
this.layout(true);
}
public void swap2() {
/*This should be split into a separate
method and called only once to avoid recreating them.*/
anotherField1 = new TextField<String>();
contentPanel.add(anotherField1);
anotherField2 = new TextField<String>();
contentPanel.add(anotherField2);
this.layout(true);
}
最重要的部分是 this.layout(true)
强制它刷新您的布局,
关于java - 我可以在 GXT 中的鼠标单击事件上将 ContentPanel 添加到 ContentPanel 中吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10504671/