Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JList maximum capacity???  RSS feed

 
Noah Carroll
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that displays all of the contents in a given folder on my computer. The weird thing is that the list will show at a maximum 20 objects. I don't even know where to begin, does anyone know what to do?? Thanks in advance!
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using JList for the list there is no maximum number of items. The problem you might be encountering is that the JList doesn't support scrollbars. The AWT List automatically includes scrollbars if they are required. To get JList to behave the same we need to add it into a ScrollPane:
JList newList = new JList();
JScrollPane scrollPane = new JScrollPane( newList );
add( scrollPane )
...
Hope this helps,
Manfred.
 
Noah Carroll
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for trying to help, but I did that from the start. When I make the window so that it doesn't show twenty items, it uses scrollbars to show the remaining twenty. Even if there is less than twenty items, it still makes the scroll bars so that they can fit twenty items.
The first time the JList is display it shows twenty items. Each time after that it shows less than that or twenty but never more. It must have something to do with the initial size.
[This message has been edited by Noah Carroll (edited January 09, 2001).]
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure what you mean by appearing. Each time the list appears after the first time? Is your list being hidden and displayed continually?
Are you starting with 20 items and then trying to dynamically alter the list contents (add or delete items)? If you are doing the dynamic list stuff you need to create a ListModel. You can then use the ListModel as a Vector and add or remove elements.
For example:
DefaultListModel model = new DefaultListModel()
model.addElement("One");
model.addElement("Two");
...
model.addElement("Twenty");
// Use model during creation of JList.
JList list = new JList( model );
To get the model from the list (in some callback) use:
DefaultListModel model = (DefaultListModel)list.getListModel();
model.addElement("Twenty One");
The list scrollbar should resize automatically after adding or removing items from the model.
Manfred.
[This message has been edited by Manfred Leonhardt (edited January 10, 2001).]
 
Noah Carroll
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all of your help. I am dynamically changing the contents of my list. The problem is that every time I alter the contents I completely change them, not just one or two things. I discovered it is easier to not use the ListModel like I had been and I have it work great.
 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai how do u make a jlist a mutilple selction one??
if so give the codes.
selvas
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!