Solved

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

Posted on 2006-07-24
5
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

749 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