?
Solved

question regarding JTable

Posted on 2001-09-11
5
Medium Priority
?
357 Views
Last Modified: 2012-06-27
Hi,
       I have  a JTable which is enclosed in a JScrollPane.There are lot of rows in the table so that the total is not visible.vertical scroll bar is present.I have to move the scroll bar down to see some of the rows at the last.At this scenario,if I add a row to the table, the scroll pane is not displaying the added row(last row).it is not scrolling down to display it.How to programatically scroll down in a table if some row is added or selected
thanks in advance,
YamunaiThuraivan
0
Comment
Question by:YamunaiThuraivan
[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
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
Ovi earned 150 total points
ID: 6475805
something like

Rectangle r = table.getCellRect(row, col); // returns the rectangle of a cell from your last row added

tableScrollPane.getViewport().scrollRectToVisible(r);
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6475812
The two method calls must be used in the 'addRow' portion of your code.
0
 
LVL 92

Expert Comment

by:objects
ID: 6475886
You need to define a TableModelListener and a TreeSelectionListener that scrolls to the added/selected row.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6475891
Aren't the listeners unnecesary in this case too ?
0
 
LVL 92

Expert Comment

by:objects
ID: 6475926
It's a far more flexible way to do it. The addRow() may not (and does not need) access to the table or the scroll pane. Additionally it is possible to add rows to the table without calling addRow() thus subverting your auto scrolling.
By implementing it as a TreeModelistener, you not only ensure it's called whenever a row is added, but you also have full control over it.

Ignore the mention of the TreeSelectionListener I misread the question.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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