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

  • Home
  • SEARCH
  • 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 9241163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:19:17+00:00 2026-06-18T08:19:17+00:00

I have a problem in removing an element from a JList, my application is

  • 0

I have a problem in removing an element from a JList, my application is a client server application, the client has the JList (The view). The server have the actual data of the JList in the form of vector. When a certain action occurs on the client the server has to remove an element from the vector and then update the view on the client. I tried to get the vector after removing from the server and then construct a new JList, then set it at the view, but no update occurs.

What are some possible ways to do that?

note: i used the DefaultListModel like that:

DefaultListModel model=(DefaultListModel)myList.getModel();
model.removeElement(myElement);
myList.setModel(model);

but it gives a ClassCastException at runtime, it says that javax.swing.JList cannot be cast to javax.swing.DefaultListModel

  • 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-06-18T08:19:18+00:00Added an answer on June 18, 2026 at 8:19 am

    You can add elements to a list by just passing it a Vector in the constructor or using the setListData method, but that is not the best way to do it.

    You would usually want to use a ListModel implementation like DefaultListModel. It defines methods for handling data (addElement, removeElement,…).

    You could reduce the amount of exchanged data between the server and the client(s) by querying the server for the removed element only and not getting all the data.

    Update: Now I see you are using a model. The default implementation of a JList model is not of type DefaultListModel. You can set the model in the JList constructor, when you instantiate your JList at the beginning.

    DefaultListModel model = new DefaultListModel();
    JList list = new JList(model);
    

    Don’t instantiate it again, you need to do that only once. Then, you can use the code you posted, but you don’t have to call the setModel() method after you remove an element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem removing an XML element from my doc. I have searched
I have an iPhone application that pulls some JSON data from a server and
I have problem with show or hide form in Window Form Application. I start
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have a page with one form (i.e. a element that submits data to
I have a problem with Updating Form Element Look and Feel under Update Panel
I have a problem removing breakpoints that are set when I attach to a
I have problem with UIWebView delay when the load image from url. In my
I have problem while loading data into html select when users press or click
I want to delete event from fullCalender and I face problem with removing the

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.