How to release JScrollpane to make it not always down?

I added the following code to my project in order to get JScrollPane to automatically lower to the bottom after user performance selection, however, when I tried to drag the scroll to go to the beginning, it still had to do a scroll down to the end, and I want to ask any solution to solve it? Thanks in advance.

private void autoScrollToBottom() {
    sdPanel.getTabScrollPane().getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {

        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            e.getAdjustable().setValue(e.getAdjustable().getMaximum());
        }
    });
}
+3
source share
1 answer

try using some boolean flag that will indicate whether to move your scroll bar. Set for the parameter truewhen you perform the correct action, and then in your code:

@Override
  public void adjustmentValueChanged(AdjustmentEvent e) {
  if(isScrollingDownRequired) {
    e.getAdjustable().setValue(e.getAdjustable().getMaximum());
    isScrollingDownRequired = false;
  }
}
+3
source

All Articles