• Post Reply Bookmark Topic Watch Topic
  • New Topic

About JList listener

 
Shay Gaghe
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
 
Wilfried LAURENT
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!