Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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;
        sb.setValue(ev.getValue());
    }
// 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.

 

 

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