Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic