• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to update JList

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. Cant make sense out of this one.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Every plan is a little cooler if you have a blimp. And a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic