Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6546289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:41:23+00:00 2026-05-25T11:41:23+00:00

I have two JList s. List A has these elements: 1 two 78 item4

  • 0

I have two JLists.

List A has these elements:

  • 1
  • two
  • 78
  • item4

List B that is for now empty.

My frame has these two list and a button Verify. Once I click on the button, the selected item of List A gets verified whether it is an integer. If so, the selected item has to be transfered to List B and removed from List A.

What I did so far is when clicking on the button, the item get copied but once I selected another item the previous one get replaced with the new item which I don’t want.

How can transfer (append) the item to the other list and remove it from the first one, this way I have got finally the list with all the items without being replaced by the new items.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:41:23+00:00Added an answer on May 25, 2026 at 11:41 am

    Use a DefaultListModel.

    DefaultListModel dlmA = new DefaultListModel(); // For list A
    dlmA.addElement(1);
    dlmA.addElement("two");
    dlmA.addElement(78);
    dlmA.addElement("item4");
    
    listA.setModel(dlmA);
    

    Now, the same for your list B.

    DefaultListModel dlmB = new DefaultListModel(); // For list B
    listB.setModel(dlmB);
    

    If you want to add items to your second list, just add them to the DefaultListModel dlmB. This means you have to keep a reference to dlmB in your working class, this way you can add elements to it inside the ActionListener of your button.

    public void actionPerformed(ActionEvent evt)
    {
        // Perform your checks. If you want to add it to list B, use:
        dlmB.addElement(yourNewElem);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two JList on a swing GUI. Now I want that when a
I have two classes that extend the activity class. Each class has it's own
I have a JList with items that I want to show two values. Is
I have two applications written in Java that communicate with each other using XML
I have two elements: <input a> <input b onclick=...> When b is clicked, I
I have a problem with my two JList components. I created and placed on
I have two date fields that I need to join on. The first is
I have two BizTalk 2010 servers that belong to the same BizTalk group. They
I have two items in the Dropdown list and i have the code for
I have two DataGridViews that have the same column schema (although two different DataViews

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.