1

I have an app that uses inputs from an ArrayList (listOne) to create Component entries.

At one point I want to repopulate the sidemenu with elements from a second ArrayList (listTwo, that is, in fact, a modification of listOne).

My problem is that the items from both lists appear in the sidemenu.

How can I refresh the sidemenu, so it only shows the items of the new list?

Any kind help would be appreciated.

Here is what I have so far:

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);
    }

}
rainer
  • 3,295
  • 5
  • 34
  • 50
  • Using something like `tb.remove()` or `tb.removeAll()` is inadvisable as you are hacking our internal implementation of the toolbar. – Shai Almog Dec 30 '17 at 05:35

1 Answers1

1

I found a way to do this, but I don't know, if it is ideal:

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);
}
rainer
  • 3,295
  • 5
  • 34
  • 50
  • I would recommend just doing `c.removeAll()` then adding new entries into c rather than removing the container from the parent and adding it again. – Shai Almog Dec 30 '17 at 05:36