EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

JScrollPane with non-continuous drag


Author: Thomas Wernitz

Here is a FixedScrollPane which uses a bugfixed BoundedRangeModel. The original JScrollPane uses DefaultBoundedRangeModel, which does not honour the valueIsAdjusting property. This one does! That means if you drag the thumb of a scrollbar the View only updates after you release the mouse. Very nice for those painfully slow scrolling swing apps.

Check it out.


//--------------------------------------------------------------------
import java.awt.*;
import javax.swing.*;

public class FixedScrollPane extends JScrollPane {

  public FixedScrollPane(Component view, int vsbPolicy, int hsbPolicy) {
    super(view, vsbPolicy, hsbPolicy);
  }

  public FixedScrollPane(Component view) {
    super(view, VERTICAL_SCROLLBAR_AS_NEEDED,
HORIZONTAL_SCROLLBAR_AS_NEEDED);
  }

  public FixedScrollPane(int vsbPolicy, int hsbPolicy) {
    super(null, vsbPolicy, hsbPolicy);
  }


  public FixedScrollPane() {
    super(null, VERTICAL_SCROLLBAR_AS_NEEDED,
HORIZONTAL_SCROLLBAR_AS_NEEDED);
  }

  public JScrollBar createVerticalScrollBar() {
    JScrollBar sb = super.createVerticalScrollBar();
    sb.setModel(new FixedBoundedRangeModel(0, 10, 0, 100));
    return sb;
  }

  public JScrollBar createHorizontalScrollBar() {
    JScrollBar sb = super.createHorizontalScrollBar();
    sb.setModel(new FixedBoundedRangeModel(0, 10, 0, 100));
    return sb;
  }

}

//--------------------------------------------------------------------

import javax.swing.*;

public class FixedBoundedRangeModel extends DefaultBoundedRangeModel {

  public FixedBoundedRangeModel() {}

  public FixedBoundedRangeModel(int value, int extent, int min, int max)
{
    super(value, extent, min, max);
  }

  protected void fireStateChanged() {
    if (! getValueIsAdjusting()) 
      super.fireStateChanged();
  }   

}


Posted On: 3-Jun-1999

internet.commerce



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy