在我的应用程序中,我想重新加载表单。问题是,每次重新加载表单时,现有项目都会保留在屏幕上,随后会添加新项目。
例如,有两个按钮:buttonOne和buttonTwo。两者都在容器内。容器被添加到表单中。
当我重新加载表单时,buttonOne和buttonTwo再次添加到现有的两个按钮。当我再次重新加载时,屏幕上的按钮一和二是四次。
我试过了:
form.removeAll();
containerButton.removeAll();
containerButton.remove();
form.repaint();
form.refreshTheme();
// reload the form
channels ();
// the class
public Form form = new Form(new BoxLayout(2));
public void channels() {
container.add (buttonOne).add(buttonTwo);
form.add (containerButton);
}
这种方法无法解决问题。我错过了什么?
在此先感谢您的回复。
删除所有将删除Container
中的组件(在本例中为表单内容窗格),但不会通过层次结构删除它们。
都:
form.repaint();
form.refreshTheme();
更改层次结构时使用的API是否正确。你需要使用revalidate()
或animateLayout()
。
“重新加载”不是Codename One中存在的概念,因为小部件不知道您的数据。一个常见的傻瓜式技巧是从头开始重新创建表单并显示它。