Example usage for javax.swing BoundedRangeModel getMaximum

List of usage examples for javax.swing BoundedRangeModel getMaximum

Introduction

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

Prototype

int getMaximum();

Source Link

Document

Returns the model's maximum.

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);
    System.out.println(model.getMaximum());

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

    frame.setSize(300, 200);/*from w  ww. j a  v a2  s . co m*/
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Creates a JSlider built//from  ww  w . j a  va  2s .  c o  m
 * using a {@link DefaultBoundedRangeModel} and 
 * containing a {@link MouseWheelListener} 
 * and some usual default settings
 * 
 * @param model
 * @return the corresponding {@link JSlider}
 */
public static JSlider createJSlider(final BoundedRangeModel model) {
    final JSlider slider = new JSlider(model);
    slider.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            slider.setValue(-e.getWheelRotation() * model.getMaximum() / 100 + model.getValue());
        }
    });
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    //      slider.setMajorTickSpacing(model.getMaximum()/2);
    //      slider.setMinorTickSpacing(model.getMaximum()/10);
    //      slider.setSnapToTicks(true);
    return slider;
}

From source file:Sketch.java

protected void init(BoundedRangeModel m) {
    setModel(m);//from  ww w.  j  ava 2s . c  o  m
    valuePerRevolution = m.getMaximum() - m.getMinimum();
    setMinimumSize(new Dimension(80, 80));
    setPreferredSize(new Dimension(80, 80));
    updateUI();
}

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

private void recalcScrollBar(Plot plot) {
    if (plot instanceof XYPlot) {
        XYPlot hvp = (XYPlot) plot;/*from w ww  .j a v  a 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./*  ww w  .  j a v a 2s. c o 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);
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java

/**
 * Overrides Component#setBounds(int, int, int, int) in order to determine
 * whether an automatic scroll of #chatTextPane to its bottom will be
 * necessary at a later time in order to keep its vertical scroll bar to its
 * bottom after the realization of the resize if it is at its bottom before
 * the resize.//  w w w  .  j  av  a2 s. c o m
 */
@Override
public void setBounds(int x, int y, int width, int height) {
    synchronized (scrollToBottomRunnable) {
        JScrollBar verticalScrollBar = getVerticalScrollBar();

        if (verticalScrollBar != null) {
            BoundedRangeModel verticalScrollBarModel = verticalScrollBar.getModel();

            if ((verticalScrollBarModel.getValue()
                    + verticalScrollBarModel.getExtent() >= verticalScrollBarModel.getMaximum())
                    || !verticalScrollBar.isVisible())
                scrollToBottomIsPending = true;
        }
    }

    super.setBounds(x, y, width, height);
}

From source file:org.jcurl.zui.piccolo.BroomPromptSimple.java

private int ratio2value(final double ra, final BoundedRangeModel r) {
    return r.getMaximum() + (int) ((r.getMinimum() - r.getMaximum()) * ra);
}