Solved

question regarding JTable

Posted on 2001-09-11
5
352 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
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
Ovi earned 50 total points
Comment Utility
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
Comment Utility
The two method calls must be used in the 'addRow' portion of your code.
0
 
LVL 92

Expert Comment

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

Expert Comment

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

Expert Comment

by:objects
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 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

10 Experts available now in Live!

Get 1:1 Help Now