简体   繁体   English

JList的,JScrollPane的

[英]JList,JScrollPane

My JList has >100 values. 我的JList的值> 100。 when the screen is loaded the i have set the selected index of the list to 50 and added the JList to a JScrollPane. 当加载屏幕时,我将列表的选定索引设置为50,并将JList添加到JScrollPane。 the value is getting selected but the JScrollPane is not getting adjusted to display that value. 该值被选中,但JScrollPane未被调整为显示该值。 can anyone pleases tel me how to do that. 任何人都可以打电话给我怎么做。

list.ensureIndexIsVisible(list.getSelectedIndex()); should be enough. 应该够了。

There are the following. 有以下内容。

Rectangle rect = list.getCellBounds(list.getSelectedIndex(), list.getSelectedIndex());
list.scrollRectToVisible(rect);

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

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