My JList Appears too big
I have an array dimensioned to 100 elements and a JList that displays those elements, however, this array does not always have 100 elements in it yet the JList displays a ton of blank space after the last element in the array, (presumably that would fit the other elements if they were there), is there a way to get rid of this blank space?
thanks, lateralus
> however, this array does not always have 100 elements in it yet
If you declare an array to have 100 elements, then it does have 100 elements.
Array lengths don't change, as they might in a language that allows them to be
"dimensioned" or "redimensioned". And therein lies the problem: if you create a
JList to display a list based on a (read only) array then the list will show as many
items as there are items in the array.
Have a read of the API documentation
(http://java.sun.com/javase/6/docs/api/javax/swing/JList.html) and Sun's Tutorial
and Developer Connection articles that are linked to from there.
You could create an array that was only as big as it needed to be and use JList's
setListData(). Or, if the contents of the list is more dynamic, use a ListModel to
construct the JList. The ListModel interface is implemented by DefaultListModel
which provides methods for adding and removing elements.