rzvika3
asked on
updating JList
I have a JList (in a scroll panel) and its model is a Vector.
the user can add to this vector elements and i can see them added to the list (by doing setModel(vector) and then repaint()), but if there are a lot of lines, the scrool panel does not work.
what can i do?
thank you!
the user can add to this vector elements and i can see them added to the list (by doing setModel(vector) and then repaint()), but if there are a lot of lines, the scrool panel does not work.
what can i do?
thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you want to hold your data in your vector, you'd better implement your own ListModel.
you have to extend AbstractListModel and
implement those methods
getElementAt(int)
getSize()
whenever data in your model changes you should call one of these methods
fireContentsChanged(Object , int, int)
fireIntervalAdded(Object, int, int)
fireIntervalRemoved(Object , int, int)
and AbstractListModel will inform the UI part about changes in the Model, UI part will
ask you about the new data and repaint itself.
So you are holding the data in your favourite Vector :), you can implement whatever methods you
need for modifing it and JList just paints it ...
(you can look at the sources of the DefaultListModel to see how it is implemented ...)
heyhey
you have to extend AbstractListModel and
implement those methods
getElementAt(int)
getSize()
whenever data in your model changes you should call one of these methods
fireContentsChanged(Object
fireIntervalAdded(Object, int, int)
fireIntervalRemoved(Object
and AbstractListModel will inform the UI part about changes in the Model, UI part will
ask you about the new data and repaint itself.
So you are holding the data in your favourite Vector :), you can implement whatever methods you
need for modifing it and JList just paints it ...
(you can look at the sources of the DefaultListModel to see how it is implemented ...)
heyhey
ASKER
i knew about this thing (partly), but if i have the data in vector and i want to add to this vector and remove from it, how can i 'link' it to the list model so that it will get the vector at the start and every time i add an element, it will be added to the vector.