java - How can I remove a text from my jlist? -


i can add element jlist, how can remove element selected?

here code:

defaultlistmodel<string> model = new defaultlistmodel<>();      button1.addactionlistener(new actionlistener() {         @override         public void actionperformed(actionevent e) {             // int n = joptionpane.showconfirmdialog(jframe.this,"clicked?");system.out.println(n);              string name = textfield1.gettext();              model.addelement(name);             custlist.setmodel(model);         }     });      button2.addactionlistener(new actionlistener() {         public void actionperformed(actionevent e) {         }     }); 

you can use removeelement method remove object.

here example

public static void main(string[] args) {         defaultlistmodel<string> model = new defaultlistmodel<>();         model.addelement("1");         model.addelement("2");         model.addelement("3");         system.out.println(model);//prints [1, 2, 3]         model.removeelement("1");         system.out.println(model);//prints [2, 3]     } 

Comments