简体   繁体   中英

How do I set a JScrollPane to a fixed Maximum size around a JList

My program creates a series of JScrollPanes each containing a JList. The JList displays vertically and each one has a fixed number of lines. The initial size of the container they are in isn't big enough to display the complete JList, thus the scrollpane, but can be resized.

I want each JScrollPane to stop growing when it reaches a size sufficient to display the complete JList.

I've tried setting the JList SetVisibileRowCount and then setting the ScrollPane's MaximumSize to the MaximumSize of the JList, but it seems to have no affect.

Any suggestions?

This example shows one approach: It invokes setVisibleRowCount() dynamically to limit the maximum size. It may help you construct an sscce .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM