Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
wefewf 2 42
commonTwo  challenge 63 98
count7 challenge 12 69
recursion example 16 68
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

12 Experts available now in Live!

Get 1:1 Help Now