void (ComponentEvent e) { JScrollPane scrollPane = ComponentUtil.getScrollPane(myComponent); if (scrollPane != null) { final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); final JScrollBar horizontalScrollBar = scrollPane.getVerticalScrollBar(); final AdjustmentListener listener = new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { updateCurrentSelection(); } }; if (verticalScrollBar != null) verticalScrollBar.addAdjustmentListener(listener); if (horizontalScrollBar != null) horizontalScrollBar.addAdjustmentListener(listener); list.removeComponentListener(this); } }