This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to update JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to update JList " Watch "How to update JList " New topic
Author

How to update JList

Seema Sharma
Ranch Hand

Joined: May 24, 2007
Posts: 78
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

Joined: Jul 26, 2007
Posts: 10167
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Seema Sharma
Ranch Hand

Joined: May 24, 2007
Posts: 78
AbstractListModel is not showing any clear method. Please let me know how to clear the list.

Thanks in advance,
Seema
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

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

Joined: May 24, 2007
Posts: 78
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

Joined: Jul 26, 2007
Posts: 10167
    
    8

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

Joined: May 24, 2007
Posts: 78
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

Joined: Jul 26, 2007
Posts: 10167
    
    8

Sorry. Cant make sense out of this one.
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
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
 
Don't get me started about those stupid light bulbs.
 
subject: How to update JList
 
Similar Threads
JToolTip displays JList selected text, later
drag and drop DND click, then move??
JList : how to add one simple element to a existing list??
Clearing a JList
JList SelectionForeground problem when BOLD