Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to update JList

 
Seema Sharma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please let me know how to update JList with new elements. I have used the below code & it gives ClassCastException.




Thanks in advance,
Seema
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Seema Sharma:
Hi,
Please let me know how to update JList with new elements. I have used the below code & it gives ClassCastException.


The default model for JList is AbstractListModel and not DefaultListModel.
That is causing the class cast exception.
 
Seema Sharma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AbstractListModel is not showing any clear method. Please let me know how to clear the list.

Thanks in advance,
Seema
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Seema Sharma:
AbstractListModel is not showing any clear method. Please let me know how to clear the list.

Thanks in advance,
Seema


Just use and your existing code will run with no problems.

Also take a look at these
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html
 
Seema Sharma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing Help page.A Text is entered in textfield and on pressing search button, it searches the text in HTML document & adds HTML document name to jlist.


Please check my code which throws Runtime exception at editor.read(reader, htmlDoc) and let me know what went wrong.


Thanks,
Seema
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Seema Sharma:
Please check my code which throws Runtime exception at editor.read(reader, htmlDoc) and let me know what went wrong.



Post your stack trace.
 
Seema Sharma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats happens is on searching the text for the first time, Jlist is updated properly. When new search text is entered in textfield and button is clicked, the following error comes up:


Please help me in knowing what went wrong. Thanks in advance.

Regards,
Seema
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. Cant make sense out of this one.
 
Guido Sautter
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seema,

I don't actually know what's going wrong with your code, but you might consider creating your own implementation of ListModel, which is pretty easy and straightforward if you extend AbstractListModel. Then, keep a reference to the list model in your surrounding code, and you can do the updates easily.

Hope that helps,
Guido
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic