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

x
?
Solved

programmatically setting a scroll bar

Posted on 2002-06-06
3
Medium Priority
?
257 Views
Last Modified: 2010-08-05
I have a JScrollpane managing a (dynamic) JTable, and would like to scroll to the appropriate row when some action is taken.  As stated above, my table is dynamic, and for the purpose of this example, let's say that it will display either 10 rows or 20 rows of data.

The problem is that my call to "getMaximum()" does not seem to give me the correct results:

    JScrollBar theScrollBar =
      scrollPane.getVerticalScrollBar();
    double rowPosition =
          ( (i * 1.0) / sortModel.getRowCount() ) *
          ( (double)theScrollBar.getMaximum() );
    theScrollBar.setValue((int)rowPosition);

I placed some debug in my code, and sortMode.getRowCount() DOES give me either 10 or 20, as expected.  However, getMaximum seems to not know that the table is now 10 versus 20, or vice versa.
0
Comment
Question by:happyloman
[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
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 600 total points
ID: 7060408
To scroll to a particular row try the following:

table.scrollRectToVisible(table.getCellRect(row, 0, true));
0
 

Author Comment

by:happyloman
ID: 7062799
Objects,

I tried your code, and it has the same behavior.

WHen the table goes from 10 to 20, the code is OK
When the table goes from 20 to 10, the code is NOT OK
(the table gets scrolled to the middle, but the cell I want is a the way way bottom.  It is not in
the viewport)
0
 
LVL 92

Expert Comment

by:objects
ID: 7063564
Sounds like there may be a problem with how you are manipulating the data in your table.
Can you post your code.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
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