Example usage for javax.swing BoundedRangeModel setMinimum

List of usage examples for javax.swing BoundedRangeModel setMinimum

Introduction

In this page you can find the example usage for javax.swing BoundedRangeModel setMinimum.

Prototype

void setMinimum(int newMinimum);

Source Link

Document

Sets the model's minimum to newMinimum.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    ChangeListener changeListener = new BoundedChangeListener();
    JScrollBar anotherJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    BoundedRangeModel model = anotherJScrollBar.getModel();
    model.addChangeListener(changeListener);
    model.setMinimum(10);

    JFrame frame = new JFrame("ScrollBars R Us");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(anotherJScrollBar, BorderLayout.NORTH);

    frame.setSize(300, 200);/*from w  w  w  . ja  v  a 2s  . c  om*/
    frame.setVisible(true);
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

private void recalcScrollBar(Plot plot) {
    if (plot instanceof XYPlot) {
        XYPlot hvp = (XYPlot) plot;// w  w w  .j  a va  2s.c om
        ValueAxis axis = hvp.getDomainAxis();

        axis.setLowerMargin(0);
        axis.setUpperMargin(0);

        Range rng = axis.getRange();

        BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel();
        int len = scrollBarModel.getMaximum() - scrollBarModel.getMinimum();
        if (rng.getLength() > 0) {
            scrollFactor = len / rng.getLength();
        }

        double dblow = rng.getLowerBound();
        int ilow = (int) (dblow * scrollFactor);
        scrollBarModel.setMinimum(ilow);
        int val = ilow;
        scrollBarModel.setValue(val);

        double dbup = rng.getUpperBound();
        int iup = (int) (dbup * scrollFactor);
        scrollBarModel.setMaximum(iup);
        int ext = iup - ilow;
        scrollBarModel.setExtent(ext);

        scrollBarModel.addChangeListener(this);
    }
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * Recalculates the scrollbar settings./*from   w  w  w.  ja v a  2 s .com*/
 * 
 * @param plot  the plot.
 */
private void recalcScrollBar(final Plot plot) {
    if (plot instanceof XYPlot) {
        final XYPlot hvp = (XYPlot) plot;
        final ValueAxis axis = hvp.getDomainAxis();

        axis.setLowerMargin(0);
        axis.setUpperMargin(0);

        final Range rng = axis.getRange();

        final BoundedRangeModel scrollBarModel = this.scrollBar.getModel();
        final int len = scrollBarModel.getMaximum() - scrollBarModel.getMinimum();
        if (rng.getLength() > 0) {
            this.scrollFactor = len / rng.getLength();
        }

        final double dblow = rng.getLowerBound();
        final int ilow = (int) (dblow * this.scrollFactor);
        scrollBarModel.setMinimum(ilow);
        final int val = ilow;
        scrollBarModel.setValue(val);

        final double dbup = rng.getUpperBound();
        final int iup = (int) (dbup * this.scrollFactor);
        scrollBarModel.setMaximum(iup);
        final int ext = iup - ilow;
        scrollBarModel.setExtent(ext);

        scrollBarModel.addChangeListener(this);
    }
}