This discussion is archived
2 Replies Latest reply: Oct 7, 2004 7:13 AM by 807587 RSS


807587 Newbie
Currently Being Moderated

is there a way to specify an increment step for the dragging
mode of a scroll bar just like unit and block increments can
be defined or not ?
I'm implementing Scrollable and I nearly succeeded in specifying
the scrolling behaviour that I want but it gets ruined by the

  • 1. Re: dragScrollIncrement
    807587 Newbie
    Currently Being Moderated
    I'm not sure what your goal is, what you're trying to do since you haven't made that clear,
    but I'd suggest waiting until the dragging (tracking) is over before adjusting anything -- reacting
    as the tracking is occurring can be costly, not to mention distracting to the user.

    Anyway, there is nothing in the Scrollable interface here for tracking, but you can add an AdjustmentListener
    to the JScrollBar and react when the dragging is done. I hadn't done this before, so I whipped up the
    following demo, and to my surpise, the events being emitted aren't what I expected -- run the
    following demo, tracking the horizontal scroll bar as well as clicking for unit and block changes,
    and you will see what I'm alluding to.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyTable {
        public static void main(String[] args) {
            JTable table = new JTable(30,20);
            JScrollPane sp = new JScrollPane(table);
            sp.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener(){
                public void adjustmentValueChanged(AdjustmentEvent e) {
                    if (e.getAdjustmentType() == AdjustmentEvent.TRACK && !e.getValueIsAdjusting())
                        System.out.println("done tracking");
            JFrame f = new JFrame("MyTable");
            f.setSize(600, 400);
    So the adjustment type seems to always be TRACK. Perhaps it will be enough to react when
    valueIsAdjusting is false...
  • 2. Re: dragScrollIncrement
    807587 Newbie
    Currently Being Moderated

    you've helped me a lot so as the scrolling of my home made
    table fits the columns sizes. I would not want to see your
    work spoiled by the drag (i.e. the left column not adjusted to the
    left hand side of the JScrollPane, at least at the end of the drag).
    And I think I can once again get help from your code ;-).

    Will get back to you on this.