Link to home
Start Free TrialLog in
Avatar of isuhendro
isuhendroFlag for Singapore

asked on

How to reset JList?

how to clear all items inside a JList?

I have tried using

trackList.removeAll(()

but does no effect.

I also tried using code below:

Object[] blank = {""};
trackList.setListData(blank);

.. it will clear up, but change this list as if setVisibleRowCount = 1.

Thanks & regards


ASKER CERTIFIED SOLUTION
Avatar of ADSLMark
ADSLMark

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ADSLMark
ADSLMark

I also have a probable cause of your problem, the GUI doesn't get updated after a "removeAll()", so maybe all the elements are removed, but the GUI doesn't know yet. It might work if you do a repaint().

Mark
Avatar of isuhendro

ASKER

hello Mark,

thanks for your reply. I prefer not to using model for this JList, otherwise will need to change codes at other part.

btw repaint() will not help as well..
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok then Mark... just found out that the problem with setVisibleCountRow become 1, is related to the BorderLayout... not to the list itself.. so i will use previous solution. Btw what is the advantage of using DefaultListModel ?
Thanks & regards.
Better design, more functionality for free.
Take a look at the model-view-controller design pattern. You have one model with maybe multiple views and multiple controllers. This way the model/view/controller are separated from each other which makes extending it easy etc.
Many advantages by using established design patterns.. anyway, it's not necessary. :-)

Mark