Solved

question regarding JTable

Posted on 2001-09-11
5
353 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
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

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
basic hardware to learn oop advanced design patterns 3 88
HashMap Vs TreeMap 12 55
Java Options in Zimbra Server 2 44
Java SE 8u111  Lot of stuff broke 11 52
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
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…

932 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

16 Experts available now in Live!

Get 1:1 Help Now