我在代码名为One的应用程序中无法使UI正常工作.我将其提炼为加载ParentContainer的"starter应用程序".
ParentContainer有一个按钮,用于更新子容器.它实际上只是在您单击按钮时删除和添加标签.
THE PROBLEM: The ChildContainer doesn't seem to want to render the label? Its empty. If I force a hard refresh in the Simulator by ROTATING THE DEVICE then it renders the label one time. I also checked the Codename One desktop application build and see the same problem. For the Desktop Build I can resize the main window and it will render the label.
没有任何程序可以让它显示出来.invalidate()/repaint()/callSerially()
即使在我将其显示出来之后,如果我再次按下ParentContainer按钮,它也会消失.我做错了什么?任何帮助都将不胜感激.
public class BugTestApp extends Lifecycle {
@Override
public void runApp() {
Form hi = new Form("Hi World");
hi.setLayout(new BorderLayout());
ParentContainer container = new ParentContainer();
container.init();
hi.add(BorderLayout.CENTER, container);
hi.show();
}
}
public class ParentContainer extends Container {
ChildContainer childContainer=null;
public void init() {
this.setLayout(new BorderLayout());
Button btnFilterCategory = new Button("CLICK ME TO ACTIVATE");
btnFilterCategory.addActionListener(e-> {
childContainer.reloadAll();
});
this.add(BorderLayout.NORTH,btnFilterCategory);
childContainer = new ChildContainer();
childContainer.initComponents();
this.add(BorderLayout.CENTER, childContainer);
}
}
public class ChildContainer extends Container {
public void initComponents() {
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
reloadAll();
}
public void reloadAll() {
this.removeAll();
this.add(new Label("This is a label."));
this.repaint();
}
}