Loading...
Logo
Processing Forum
Hi everyone,

I'm trying to delete multilist items. It's supposedly possible in the library's example -  ControlP5multiList.

Where in line 68 it says:
Copy code
    Copy code
    1.   //
    2.  uncomment the line below to remove a multilist item when clicked.
    3.   theEvent.controller().remove();

    If you try to run it, you get an error. Here is the whole example code:
    Copy code
    1. /**
    2.  * ControlP5 MultiList
    3.  * by andreas schlegel, 2009
    4.  */

    5. import controlP5.*;

    6. ControlP5 controlP5;
    7. MultiList l;

    8. void setup() {
    9.   size(1024,768);
    10.   frameRate(30);
    11.   controlP5 = new ControlP5(this);
    12.   
    13.   // add a multiList to controlP5.
    14.   // elements of the list have default dimensions
    15.   // here, a width of 100 and a height of 12
    16.   l = controlP5.addMultiList("myList",0,10,100,12);
    17.   
    18.   // create a multiListButton which we will use to
    19.   // add new buttons to the multilist
    20.   MultiListButton b;
    21.   b = l.add("level1",1);
    22.   
    23.   // add items to a sublist of button "level1"
    24.   b.add("level11",11).setLabel("level1 item1");
    25.   b.add("level12",12).setLabel("level1 item2");

    26.   b = l.add("level2",2);
    27.   
    28.   int cnt = 100;
    29.   
    30.   // add some more sublists.
    31.   for(int i=0;i<10;i++) {
    32.     MultiListButton c = b.add("level2"+(i+1),20+i+1);
    33.     c.setLabel("level2 item"+(i+1));
    34.     c.setColorBackground(color(64 + 18*i,0,0));
    35.     
    36.     if(i==4) {
    37.     // changing the width and the height of a button
    38.     // will be inherited by its sublists.
    39.     c.setWidth(100);
    40.     c.setHeight(20);
    41.     }
    42.     cnt++;
    43.     
    44.     if(i==4) {
    45.       for(int j=0;j<10;j++) {
    46.         cnt++;
    47.         MultiListButton d;
    48.         d = c.add("level2"+i+""+j,250+j+1);
    49.         d.setLabel("level2 item"+(i+1)+" "+"item"+(j+1));
    50.         d.setColorBackground(color(64 + 18*j,(64 + 18*j)/2,0));
    51.         d.setId(cnt);
    52.         d.setWidth(200);
    53.       }
    54.     }
    55.   }
    56.   
    57.   MultiListButton cc = (MultiListButton)controlP5.controller("level21");
    58.   cc.setHeight(40);
    59. }


    60. void controlEvent(ControlEvent theEvent) {
    61.   println(theEvent.controller().name()+" = "+theEvent.value());  
    62.   // uncomment the line below to remove a multilist item when clicked.
    63.   theEvent.controller().remove();
    64. }


    65. void draw() {
    66.   background(0);
    67. }

    68. void keyPressed() {
    69.   if(controlP5.controller("level23")!=null) {
    70.     println("removing multilist button level23.");
    71.     controlP5.controller("level23").remove();
    72.   }
    73. }