List of usage examples for javax.swing BoundedRangeModel setValue
void setValue(int newValue);
newValue
if newValue
satisfies the model's constraints. 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.setValue(1); 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 a 2 s. c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { BoundedRangeModel model = new DefaultBoundedRangeModel(); BlockedColorLayerUI layerUI = new BlockedColorLayerUI(); JPanel p = new JPanel(new GridLayout(2, 1, 12, 12)); p.add(new JLayer<JProgressBar>(new JProgressBar(model), layerUI)); JPanel box = new JPanel(); box.add(new JButton(new AbstractAction("+10") { private int i = 0; @Override/*from ww w .ja v a2 s . c o m*/ public void actionPerformed(ActionEvent e) { model.setValue(i = (i >= 100) ? 0 : i + 10); } })); p.repaint(); JPanel panel = new JPanel(new BorderLayout()); panel.add(p, BorderLayout.NORTH); panel.add(box, BorderLayout.SOUTH); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(panel); f.setSize(320, 240); f.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 av a2 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:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void chartChanged(ChartChangeEvent event) { try {//from w ww . ja v a 2 s . com if (event.getChart() == null) { return; } BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel(); if (scrollBarModel == null) { return; } boolean chartIsZoomed = false; Plot plot = event.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot hvp = (XYPlot) plot; ValueAxis xAxis = hvp.getDomainAxis(); Range xAxisRange = xAxis.getRange(); // avoid recursion scrollBarModel.removeChangeListener(this); int low = (int) (xAxisRange.getLowerBound() * scrollFactor); scrollBarModel.setValue(low); int ext = (int) (xAxisRange.getUpperBound() * scrollFactor - low); scrollBarModel.setExtent(ext); // restore scrollBarModel.addChangeListener(this); // check if zoomed horizontally //Range hdr = hvp.getHorizontalDataRange(xAxis); Range hdr = hvp.getDataRange(xAxis); double len = hdr == null ? 0 : hdr.getLength(); chartIsZoomed |= xAxisRange.getLength() < len; } if (!chartIsZoomed && plot instanceof XYPlot) { // check if zoomed vertically XYPlot vvp = (XYPlot) plot; ValueAxis yAxis = vvp.getRangeAxis(); if (yAxis != null) { chartIsZoomed = yAxis.getLowerBound() > yMin || yAxis.getUpperBound() < yMax; } } // enable "zoom-out-buttons" if chart is zoomed // otherwise disable them chartPanButton.setEnabled(chartIsZoomed); chartZoomOutButton.setEnabled(chartIsZoomed); chartFitButton.setEnabled(chartIsZoomed); chartScrollBar.setEnabled(chartIsZoomed); if (!chartIsZoomed) { setPanMode(false); chartZoomButton.setSelected(true); } } catch (Exception e) { MsgBox.error(e.getMessage()); } }
From source file:apidemo.PanScrollZoomDemo.java
/** * Recalculates the scrollbar settings.//from w w w . j a v a 2 s .c om * * @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:apidemo.PanScrollZoomDemo.java
/** * Handles a {@link ChartChangeEvent}./*from w w w. j a v a2 s . c o m*/ * * @param event the event. */ public void chartChanged(final ChartChangeEvent event) { try { if (event.getChart() == null) { return; } final BoundedRangeModel scrollBarModel = this.scrollBar.getModel(); if (scrollBarModel == null) { return; } boolean chartIsZoomed = false; final Plot plot = event.getChart().getPlot(); if (plot instanceof XYPlot) { final XYPlot hvp = (XYPlot) plot; final ValueAxis xAxis = hvp.getDomainAxis(); final Range xAxisRange = xAxis.getRange(); // avoid recursion scrollBarModel.removeChangeListener(this); final int low = (int) (xAxisRange.getLowerBound() * this.scrollFactor); scrollBarModel.setValue(low); final int ext = (int) (xAxisRange.getUpperBound() * this.scrollFactor - low); scrollBarModel.setExtent(ext); // restore scrollBarModel.addChangeListener(this); // check if zoomed horizontally //Range hdr = hvp.getHorizontalDataRange(xAxis); final Range hdr = hvp.getDataRange(xAxis); final double len = hdr == null ? 0 : hdr.getLength(); chartIsZoomed |= xAxisRange.getLength() < len; } if (!chartIsZoomed && plot instanceof XYPlot) { // check if zoomed vertically final XYPlot vvp = (XYPlot) plot; ValueAxis yAxis = vvp.getRangeAxis(); if (yAxis != null) { chartIsZoomed = yAxis.getLowerBound() > this.primYMinMax[0] || yAxis.getUpperBound() < this.primYMinMax[1]; // right y-axis if (!chartIsZoomed && plot instanceof XYPlot) { final XYPlot xyPlot = (XYPlot) plot; yAxis = xyPlot.getRangeAxis(1); if (yAxis != null) { chartIsZoomed = yAxis.getLowerBound() > this.secondYMinMax[0] || yAxis.getUpperBound() < this.secondYMinMax[1]; } } } } // enable "zoom-out-buttons" if chart is zoomed // otherwise disable them this.panButton.setEnabled(chartIsZoomed); this.zoomOutButton.setEnabled(chartIsZoomed); this.fitButton.setEnabled(chartIsZoomed); this.scrollBar.setEnabled(chartIsZoomed); if (!chartIsZoomed) { setPanMode(false); this.zoomButton.setSelected(true); } } catch (Exception e) { e.printStackTrace(); } }