I would like to scroll down a JScrollPane
automatically when updating him. My JScrollPane contains some panels that I had time to time according to user actions.
Tests made
Existing solutions are all about JTextArea or JList. The solution below works but has the problem to override every user actions (If we manually click on the ScrollBox, it will scroll down automatically after) :
@Override
public void adjustmentValueChanged(AdjustmentEvent e){
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
}
I have tried this solution :
private void addPanel(JPanel newPanel){
scrollPanel.add(newPanel);
scrollDown();
}
private void scrollDown(){
JScrollBar vertical = scroll.getVerticalScrollBar();
vertical.setValue(vertical.getMaximum());
}
I call it just after adding a JPanel to my JScrollPane. But it scrolls not to the exact bottom but just before which is not very... clean.