• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

About JList listener  RSS feed

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Coders!
Im developing a chat program. I diside to use Jlist as a dissection protocol.
I decided to use a Jlist because I have to register such a listener that able to tell me when a new element were added to the list and in addition one that can scroll the list to old element that been previously added to the list.
I�ve looked for it in the API , I find two listeners that can do the job: ListSelectionListener and ListDataListener. I couldn�t find the difference between them both.
can anyone explain? , what the correct combination to use in my case?
Also I have some question about using Jlist,
Can I change one chars color within an element?
Does the number of elements are limited in DataList,vector , and if yes how can I reload it dynamically?
Thanks
Shay Gaghe
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Shay Gaghe:

I�ve looked for it in the API , I find two listeners that can do the job: ListSelectionListener and ListDataListener. I couldn�t find the difference between them both.
can anyone explain? , what the correct combination to use in my case?


Under the JList hide two models: A ListModel, which contains the data of your list and a ListSelectionModel, which handles the selection on your list (what element or elements are selected).
You can put a ListDataListener on a ListModel and you will the be notified when elements are added or removed (that's what you are looking for), and a ListSelectionListener on a ListSelectionModel and you will be notified when the selection changes (This one can be directly added on an instance of JList).
W.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!