Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JList setListData problem  RSS feed

 
Greenhorn
Posts: 5
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've a problem with 'refreshing' the JList. I"m using a Vector (which gets it's data from a database) to fill the JList and the JList is in a JScrollPane. I'm using a JFrame to show the JScrollPane.
My problem:
When I try to set the list data of the JList, it doesn't replace the list data which already was in the JList, but it just adds the new data (including the previous data) to the JList.
Here's an example.

JList showing the following data:
- One
- Two
- Three

Now, some new data is added to the Vector. I add 'four' to the vector. When I call JList.setListData(Vector) the JList shows this data:

- One
- Two
- Three
- One
- Two
- Three
- Four

I obviously only want the new data (one till four) and I want to get rid of the old data. Why doesn't the JList replace the previous data?

Hope someone can help me! (If you need my entire code, just leave a reply here. My code is very long, so I hope you don't need it )

Robin
 
Sheriff
Posts: 21602
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you clear() the Vector before adding the new elements? If not it will keep everything you added until that time.
 
Robin Trietsch
Greenhorn
Posts: 5
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't clear the Vector before calling JList.setListData(). I'm going to try that tomorrow. Thanks for your reply, I think that's the solution!
 
Robin Trietsch
Greenhorn
Posts: 5
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked! I tried it this morning and that was the solution! Thanks,
Robin
 
Rob Spoor
Sheriff
Posts: 21602
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!