Given a JScrollPane
containing a thousand components using some LayoutManager
. Each component can be either in a loaded or unloaded state. There are not enough resources for all to be loaded.
I'd like to have only the visible components load()
ed in memory, and the invisible components unload()
ed. When the user scrolls, a listener needs to keep updating the components' states: unload()
the previously visible, and load()
the newly visible.
- At any given moment, how do I know which components are visible?
- Can I know this without iterating the whole thousand? (as if an efficient
viewPort.getVisibleComponents()
)
I was going to have a prepared sorted list of all component Ys, then in runtime binary search the ViewPort
's Y to reach an index which may guide me to the visible ones. This failed as component Ys all returned 0 during list preparation time. This needs to be efficient.