Solved

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

Posted on 2006-07-24
5
340 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now