Solved

JScrollPane autoscroll?

Posted on 2004-04-19
4
2,675 Views
Last Modified: 2008-02-20
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.


0
Comment
Question by:b612_forever
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 10864931
1. table.scrollRectToVisible(table.getCellRect(table.getRowCount(), 0, false));

2. Similar approach, passing the regoin of the panel you want visible.


0
 
LVL 1

Author Comment

by:b612_forever
ID: 10865551
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 10865568
0
 
LVL 1

Expert Comment

by:HammanSamuel
ID: 20099663
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.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
stackato and cloud 4 85
even odd program using while loop 3 41
hibernate insert example 13 29
null output 3 25
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question