1

我有一个应用程序,它使用来自 ArrayList (listOne) 的输入来创建组件条目。

有一次,我想用第二个 ArrayList(listTwo,实际上是对 listOne 的修改)中的元素重新填充 sidemenu。

我的问题是两个列表中的项目都出现在侧面菜单中。

如何刷新侧面菜单,使其仅显示新列表的项目?

任何帮助将不胜感激。

这是我到目前为止所拥有的:

tb = hi.getToolbar();

for (String s : listOne) {
    testLabel = new Label(s);
    tb.addComponentToSideMenu(testLabel);
}


public void test () {

    tb.remove();
    tb.removeAll();
    tb.removeComponent(testLabel);
    testLabel.remove();

    for (String string : listTwo) {
        testLabel = new Label(string);
        tb.addComponentToSideMenu(testLabel);
    }

}
4

1 回答 1

1

我找到了一种方法来做到这一点,但我不知道它是否理想:

c = new Container();
c.setLayout(new BoxLayout(2));

for (String s : listOne) {
     c.add(new Label("test"));
}
tb.addComponentToSideMenu(c);


public void test () {

    c.remove(); 

    c = new Container();
    c.setLayout(new BoxLayout(2));

    for (String s : listTwo) {
        c.add(new Label("test 2"));
    }

    tb.addComponentToSideMenu(c);
}
于 2017-12-29T21:31:28.353 回答