在JScrollPane中获取显示的组件 [英] Get shown component in JScrollPane
问题描述
我有一个包含JPanel的JScrollPane.我用许多按钮填充了这个JPanel.
I have a JScrollPane containing a JPanel. I fill this JPanel with many buttons.
是否有可能获得当前显示的按钮?
Is there any possibility to get the currently shown buttons?
我知道我可以通过jpanel.getComponents()
访问JPanel的子级,但是这些都是该窗格中的所有组件.我只需要屏幕上当前显示的那些.
I know I can access the children of a JPanel via jpanel.getComponents()
but those are all components in this pane; I want only the ones that are currently on screen.
推荐答案
我假定此容器在屏幕上已经可见,然后建议
I assume that this container is already visible on the screen, then I suggest
1)从中提取 JViewPort JScrollPane ,
2) addChangeListener 到JViewPort
3)每个可见的JComponent(s)
返回矩形
3) each visible JComponent(s)
returns Rectangle
4) and Rectangle#intersects returns Boolean
value if is JComponent(s)
visible or not in JViewPort
这篇关于在JScrollPane中获取显示的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!