?
Solved

JScrollPane autoscroll?

Posted on 2004-04-19
4
Medium Priority
?
2,687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

800 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