[英]Can I add a ContentPanel into a ContentPanel on a mouse click event in GXT
I want to remove all elements from a ContentPanel on a mouse click event and add new ones. 我想在鼠标单击事件上从ContentPanel中删除所有元素并添加新元素。 It is working fine with removeAll() method, this removes all existing components.
它使用removeAll()方法正常工作,这将删除所有现有组件。 But when I want to add a new Component it is not added.
但是当我想添加一个新组件时,它不会被添加。
Maybe something like this i omitted the click handler but you should get the idea from this. 也许像这样的东西我省略了点击处理程序,但你应该从中得到这个想法。
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);
}
Most important part is this.layout(true)
to force it to refresh your layout, 最重要的部分是
this.layout(true)
强制它刷新你的布局,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.