Allign JScrollBar

Posted on 2007-11-27
Last Modified: 2010-04-21
Hello, my problem is as follows
I have a drop down menu on top and right below is a scroll bar where there are 1000 elements.
the user can either select an element from the drop down menu on top or by scrolling down in the scroll bar and selecting it manually.

the problem is that when the user selects something in the drop down above the scroll bar, the elements get properly highlighted in the scrollbar below BUT the actual SCROLLER does not scroll down to what was selected.

IE: you have a drop down menu of numbers from 1 to 10, you select 6 from the drop down menu, so on the scroll bar you should only see
6  (drop down menu where you selected 6)
6 (highlighted)

BUT this is not what happens, what happens is below:
6  (drop down menu where you selected 6)

6 IS highlighted but you have to scroll down to it to see it...

So as you can see the scroll bar doesnt adjust properly based on the selection, how can i maybe set it to always have the selected value be in the middle of the scroll bar?

thanks you
Question by:Squadless
  • 3
  • 2
LVL 24

Expert Comment

ID: 20360477
You must make the scrollbar to scroll an item into view.
It depends on the component inside the scrollbar: you must do the work in there.

LVL 92

Expert Comment

ID: 20361361

Author Comment

ID: 20361449
im an idiot, I just realized im using a jscrollpane without a jscrollbar

nonetheless this is what i have

JScrollPane jScrollPane1 = new JScrollPane();
jScrollPane1.setViewportView(plansList);//planlist is JList
jPanel8.add(jScrollPane1, BorderLayout.CENTER);

so i should add a jscrollbar to jscrollpanel and then scrollrecttovisible?
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 92

Accepted Solution

objects earned 500 total points
ID: 20361534
u should call scrollrecttovisible visible when you want it to scroll to new selection

u can create your scroller using:

JScrollPane jScrollPane1 = new JScrollPane(plansList);

Author Closing Comment

ID: 31411272
thanks worked to perfection.

Author Comment

ID: 20361587
wait nevermind, the KNOB of the scroller doesnt move :(

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

830 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