简体   繁体   English

JScrollPane中的JList

[英]JList in JScrollPane

I have a JList in a JScrollPane and want the scroll pane to behave like it would not exists (concerning preferredSize ) when the list contains less than 10 items. 我在JScrollPane有一个JList ,并且当列表包含少于10个项目时,希望滚动窗格的行为像它不存在(关于preferredSize )。 As soon as the list contains at least 10 items I want the scroll pane to have a preferred size like the list would have with 10 items. 一旦列表中至少包含10个项目,我希望滚动窗格具有首选大小,就像列表中包含10个项目一样。 How is that possible? 那怎么可能?

Use JList.setVisibleRowCount(int) . 使用JList.setVisibleRowCount(int) That will set a preferred height for the list that the scroll pane will attempt to honor. 这将为滚动窗格尝试遵循的列表设置首选高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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