Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sizing a JList

Status
Not open for further replies.

macgre

Programmer
Nov 20, 2002
2
CA
I am dynamically adding items to a JList (using setListData) but only want 5 to show at a time. I have tried using setVisibleRowCount(5) but it doesn't work. I even tried some Sys outs to see if the method worked and sure enough it tells me that the visible row count is 5 but I still have a JList that is more that 5?!?

Code can be made available on request.
 
you might try
Code:
Dimension getPreferredScrollableViewportSize()
Computes the size of the viewport needed to display visibleRowCount rows.

Honestly I have no idea if this will work, but it looks like what you may be after. ----------------------------------------
There are no onions, only magic
----------------------------------------
 
Great minds must think alike I was investigating the same and came up with this.

Code:
JScrollPane sp = new JScrollPane(this.variables = new JList());
this.varList = new Vector();
this.variables.setVisibleRowCount(5);
this.add(sp);

The problem was that setVisibleRowCount only works when the JList is contained within a JScrollPane, it is simply ignored otherwise!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top