Code
// UIManager.put("ScrollBar.alwaysShowThumb", Boolean.TRUE);
JScrollPane scroll = new JScrollPane(new JTable(24, 3));
scroll.getVerticalScrollBar().addAdjustmentListener(e -> {
JScrollBar scrollBar = (JScrollBar) e.getAdjustable();
BoundedRangeModel m = scrollBar.getModel();
int value = m.getValue();
boolean max = value == m.getMaximum() - m.getExtent();
Optional.ofNullable(scrollBar.getComponent(0))
.ifPresent(b -> b.setEnabled(!max));
boolean min = value == m.getMinimum();
Optional.ofNullable(scrollBar.getComponent(1))
.ifPresent(b -> b.setEnabled(!min));
});
References
No comments:
Post a Comment