Example usage for javax.swing BoundedRangeModel setMaximum

List of usage examples for javax.swing BoundedRangeModel setMaximum

Introduction

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

Prototype

void setMaximum(int newMaximum);

Source Link

Document

Sets the model's maximum to newMaximum.

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.setMaximum(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 va  2  s .c o m*/
    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 .ja  va  2  s  .  co m
        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   ww  w. ja  va 2 s .co  m*/
 * 
 * @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);
    }
}