Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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