How to move items from one JList to other
843806Jun 28 2007 — edited Jun 29 2007Can u pls help me out to implement this(I m using Netbeans 5.5):
I want to move items from one JList to other thru a ADD button placed between JLists, I am able to add element on Right side JList but as soon as compiler encounter removeElementAt() it throws Array Index Out of Bound Exception
and if I use
removeElement() it removes all items from left side JList and returns value false.
Pls have a look at this code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Object selItem = jList1.getSelectedValue();
int selIndex = jList1.getSelectedIndex();
DefaultListModel model = new DefaultListModel();
jList2.setModel(model);
model.addElement(selItem);
DefaultListModel modelr = new DefaultListModel();
jList1.setModel(modelr);
flag = modelr.removeElement(selItem);
//modelr.removeElementAt(selIndex);
System.out.println(flag);
}