The Artima Developer Community
Sponsored Link

Java Answers Forum
JLIST

3 replies on 1 page. Most recent reply: Dec 17, 2004 3:54 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
ricky

Posts: 8
Nickname: ricky30000
Registered: Jul, 2003

JLIST Posted: Sep 19, 2004 11:57 AM
Reply to this message Reply
Advertisement
I have stored information in a default List Model and I can add to the model easily enough and that then updates the JList. When I want to remove from the JLISt, it gets removed from the Model; but the Jlist will not update unless i resize the app or minimise it. It throws a arrayOutOfBounds exception -1 >=0. Any ideas, i have tried repaint() or revalidate() and clearing the whole list and adding it in again, but it won't let me clear it in the first place.


Yogesh

Posts: 19
Nickname: kyogesh
Registered: Sep, 2004

Re: JLIST Posted: Sep 20, 2004 12:37 AM
Reply to this message Reply
Every time u modify DefaultListModel try using JList's setModel() method

eg.
DefaultListModel dlm = new DefaultListModel();
JList list= new JList(dlm);
//try adding something to dlm;
//use setModel() now
list.setModel(dlm);
//try removing from dlm
//now use setModel() again
list.setModel(dlm);

this should update the list

if it doesn't work try sending the fragment of code
check for indices while removing from the model.

bye...

ricky

Posts: 8
Nickname: ricky30000
Registered: Jul, 2003

Re: JLIST Posted: Sep 21, 2004 11:11 AM
Reply to this message Reply
hi,

Yea tried that and it didn't work on the remove element and messed up the add element.

here is the add element.
custnameString is just from a text Field.
the model is called sampleModel.

sampleModel.addElement("Customer: " + custnameString);

here is the remove element.
int listdes = (sampleJList.getSelectedIndex());
sampleModel.removeElementAt(listdes);


When it get remove it just doesn't update the list unless u minimize it. A way round it would be to resize the window slightly, and then resize it back.

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: JLIST Posted: Dec 17, 2004 3:54 AM
Reply to this message Reply
dont remove it from list.

Remove it from listmodel.

else call repaint/validate method

Flat View: This topic has 3 replies on 1 page
Topic: How to repaint a panel Previous Topic   Next Topic Topic: an interesting JTextField question - please help!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use