[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

question regarding JTable

Posted on 2001-09-11
5
Medium Priority
?
359 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

656 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