File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JList width Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList width" Watch "JList width" New topic

JList width

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
I have a JList inside a ScrollPane. I set the vertical size by using the .setVisibleRowCount method, so now the height is always the same height, and when the number of options is large enough, it scrolls. I want to do the same kind of thing to the width, but I looked in the JList API and didn't see anything that seems to work. The width keeps changing depending on what is in the list. How can I set the width?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
give the scrollpane a preferredSize
scrollPane.setPreferredSize(new Dimension(100,200));
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
Thank you.
I agree. Here's the link:
subject: JList width
It's not a secret anymore!