Solved

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

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

Technology Partners: 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

Title # Comments Views Activity
Apps blocked by Java 9 103
SQL Insert parts by customer 12 63
Query Syntax 17 66
How to call a web service and get the results posted in a form in PHP 9 98
This article will show, step by step, how to integrate R code into a R Sweave document
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …

739 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