Link to home
Start Free TrialLog in
Avatar of b612_forever
b612_forever

asked on

JScrollPane autoscroll?

Question 1:
I put a JTable into a JScrollPane and would like to ensure the JTable always scrolled to the BOTTOM automatically.How should I code this?

Question 2:
Besides this, I have a similar porblem but instead a JTable, I am putting a custom line graph component that extends JPanel. How could I ensure that the graph always scrolled to the RIGHT automatically.


ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of b612_forever
b612_forever

ASKER

I always think that the solution should come from the JScrollPane so I can't find the solution.

Thank you very much for your help.
Here's a method you could use (a solution using JScrollPane):
--------------------
public void autoScroll(JScrollPane sPane){
        sPane.validate();
        JScrollBar vScroll = sPane.getVerticalScrollBar();
        vScroll.setValue(vScroll.getMaximum());
}
-------------------
You can include this method in your class and call it by passing the scroll pane object that is holding your table. Call this method to the event in the same place as where the table contents are initialized.