Discussion:
JScrollPane & focus
(too old to reply)
Moosa
2003-07-04 21:35:01 UTC
Permalink
Hi all. I have a JScrollPane object (with only a horizontal scroll bar). It
contains various buttons, which can be selected by a drop down menu box.
When a particular button is selected from the drop down menu box, that
button is "highlighted." The problem that I am having now is that when a
button (which is outside the current viewing area) is selected, the
horizontal scrollbar of my JScrollPane doesn't automatically scroll and
bring that button into the current viewing area. The user right now has to
manually scroll the bar to see the selected button. So my question is that
is there any way of achieving the automatic scrolling feature, when a
particular button is selected? Thank you.

--
MM
Babu Kalakrishnan
2003-07-05 10:53:02 UTC
Permalink
Post by Moosa
Hi all. I have a JScrollPane object (with only a horizontal scroll bar). It
contains various buttons, which can be selected by a drop down menu box.
When a particular button is selected from the drop down menu box, that
button is "highlighted." The problem that I am having now is that when a
button (which is outside the current viewing area) is selected, the
horizontal scrollbar of my JScrollPane doesn't automatically scroll and
bring that button into the current viewing area. The user right now has to
manually scroll the bar to see the selected button. So my question is that
is there any way of achieving the automatic scrolling feature, when a
particular button is selected? Thank you.
You could try registering a focus listener on each of the components
inside the JScrollPane, and calling scrollRectToVisible on the component
specifying the rectangle as (0,0,width,height) in the focusGained event
handler.

(Never tried this myself - but the API docs suggest that this should work)

BK

Continue reading on narkive:
Loading...