如何获取在我的JList中可见的列和行的数量? [英] How to get the number of columns and rows that are visible in my JList?

查看:269
本文介绍了如何获取在我的JList中可见的列和行的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JscrollPane内有一个JList,我正在尝试对数据进行分页,在该页面中,随着用户滚动,它会将适当数量的数据加载到屏幕上.问题是我需要弄清楚需要从文件中缓冲多少数据,而这样做的唯一方法是弄清楚需要在屏幕上显示多少数据.有谁知道如何从我的JList中获取可以显示的数字或行和列?用JListJScrollPane分页还是个好主意,还是有其他一些方法更适合在滚动面板中显示大量数据?

I have a JList that is inside of a JscrollPane and I am trying to do some pagination on the data, in which as the user scrolls it loads the appropriate amount of data onto the screen. The problem is I need to figure out how much data I need to buffer out of my file and the only way to do that is to figure out how much data needs to be displayed on the screen. Does anyone have an idea of how to get the number or rows and columns that can be displayed out of my JList? Also is doing pagination with a JList and a JScrollPane a good idea or is there some other approach that would be better suited for displaying a ton of data in a scroll panel?

谢谢

推荐答案

您可以使用JListgetFirstVisibleIndexgetLastVisibleIndex方法来计算可见时显示的项目数.

You can use getFirstVisibleIndex and getLastVisibleIndex methods of JList to calculate number of items it displays when visible.

如果滚动窗格中视口的大小发生变化,则可见行数也会发生变化.因此,如果组件可调整大小,则可能需要收听组件大小的更改.

If size of viewport in scroll pane changes then the number of visible rows will also change. So if the component is resizable you may need to listen to the change in the component size.

这篇关于如何获取在我的JList中可见的列和行的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆