Solved

How to Move Items from One List Box to Another List Box?

Posted on 2006-07-24
5
343 Views
Last Modified: 2011-09-20
I need to create 2 list boxes with some values in SWING and provide the functionality to move items from 1 list box to another using ADD / REMOVE buttons...

Please guide me how can I achieve this using SWING.
0
Comment
Question by:jaipur07
  • 2
5 Comments
 

Author Comment

by:jaipur07
ID: 17166436
any comments please. Its very urgent. Any help will be highly appriciated!!
0
 
LVL 2

Accepted Solution

by:
BarryMcGillin earned 500 total points
ID: 17167174
1. Define you JLists with ListModels

JList myList = new JList (myListModel);

Using models, you can add and delete elements from the model really easily, using listModel.addElement() and removeElement().

2. Wrt to the buttons, add a MouseListener to the button and then use the the event to add the selected items from list1 to list2.  

which would look kinda like this.
myAddButton.addMouseListener(new MouseAdaptor() {
  public void mouseClicked(MouseEvent e) {
   
    if (myList1.getSelectedItems() != null) {
        add(myList2, myList1.getSelectedItems());  //add items to list2 Model
        remove(myList1, myList1.getSelectedItems());  //Remove items from List1Model.
  }

}
}
);

Repeat this for the remove button and you should be good.
0
 
LVL 2

Expert Comment

by:BarryMcGillin
ID: 17400308
Thank u :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change the background and font colors in Notepad++ 5 114
ejb wildfly example 2 25
Cygwin - GNU GPL License 1 37
learn programming 8 42
A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question