java - Moving a String from one JList To Another -


i can't figure out how transfer string 1 jlist another. there class main creates jframe buttons on. tried rightlist.setlistdata(leftlist.getselectedvalues crossed out getselectedvalues

package multilist;  import java.awt.*; import java.awt.event.*; import java.util.list; import java.util.vector;  import javax.swing.*; import javax.swing.event.*;  public class gui extends jframe {     private jlist leftlist;     private jlist rightlist;     private jbutton movebutton;     private static string[] food = {"pizza", "spagetiti", "mac , cheese", "cheese", "morepizza"};      public gui() {         super("title");         setlayout(new flowlayout());          leftlist = new jlist(food);         leftlist.setvisiblerowcount(3);         leftlist.setselectionmode(listselectionmodel.multiple_interval_selection);         add(new jscrollpane(leftlist));          movebutton = new jbutton("move ---->");         movebutton.addactionlistener(                 new actionlistener() {                     @suppresswarnings("deprecation")                     public void actionpreformed(actionevent event) {                         rightlist.setlistdata(leftlist.getselectedvalues());                     }                      @override                     public void actionperformed(actionevent e) {                         // todo auto-generated method stub                     }                 }         );          add(movebutton);          rightlist = new jlist();         rightlist.setvisiblerowcount(3);         rightlist.setfixedcellwidth(100);         rightlist.setfixedcellheight(15);         rightlist.setselectionmode(listselectionmodel.multiple_interval_selection);         add(new jscrollpane(rightlist));     } } 

this should work:

defaultlistmodel model = (defaultlistmodel) leftlist.getmodel(); defaultlistmodel list2model = new defaultlistmodel(); int[] selected = leftlist.getselectedindices(); (int = 0; < selected.length; i++) {          list2model.addelement(model.elementat(i));     }  rightlist.setmodel(list2model); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -