Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jlist setListData resizes the Jlist Component

 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

when I call
the List resizes to accommodate the size of the arrayList. so if arrayList has 1 element the height of JList is of height 1, if 10 in the list the JList is 10 high.

I just want the list to be fixed height regardless of elements in the list. Component is wrapped in a JScrollPane

Thanks
Alan
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See: JList.setVisibleRowCount(int visibleRowCount)
 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doenst work. I tried this already. If i resize the panel ever so slightly panel then the Jlist repaint to the correct size and fixes at that point
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What layout does the container holding the JScrollPane have? Please post your SSCCE code.
 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use JGoodies layout. i just solved the issue by using

headerJList.setPrototypeCellValue("Index 1234567890");

The API explains the method.

http://docs.oracle.com/javase/6/docs/api/javax/swing/JList.html

I have 2 other panels where the Jlist is in split panes and I dont have this issue. But i dont want a split pane for this panel as I want a button (with an arrow) between the 2 lists
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic