简体   繁体   English

在for或while循环CodenameOne上的ActionListener中添加组件

[英]add component inside ActionListener on a for or while loop CodenameOne

I have an action listener like this: 我有一个这样的动作监听器:

Form hi = new Form("test");
bbb2.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent evt) {
        while(f < 10){
            hi.addComponent(new Label("test"));
            f++;
        }
    }
}

I don't understand why it skips all the addComponent . 我不明白为什么它会跳过所有的addComponent Why is this so? 为什么会这样呢?

You need to add a revalidate() or animateLayout() to the end of the method. 您需要在方法末尾添加revalidate()animateLayout() Otherwise Codename One assumes you are still adding components. 否则,Codename One会假设您仍在添加组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM