Solved

JScrollPane autoscroll?

Posted on 2004-04-19
4
2,674 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 122
solarwind tftp server 2 45
Cipher Configuration on Apache HTTPD 4 53
replace a word with other 1 40
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now