Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Jul 24, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Stabilized Scrollbars

Numerous awt Components provide their own Scrollbars when needed. However, when you first employ one explicitly, perhaps for adjusting colors, you may encounter a frustrating problem. On some platforms the Scrollbar moves as expected as you drag it with the mouse, but jumps back to its original position when the mouse button is released. You can overcome this problem in the listener that you provide for the Scrollbar's events:
public void adjustmentValueChanged(
            AdjustmentEvent ev) {
    Component co = ev.getSource();
    if (co instanceof Scrollbar) {
        Scrollbar sb = (Scrollbar)co;
// Your other code here

Surprisingly this is all it takes to stabilize Scrollbars on all platforms. If you have no listener for changes in scrolled values, you could extend the Scrollbar class itself with the above method.
Tom Yarker
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date