List of usage examples for javax.swing JScrollBar setValue
@BeanProperty(bound = false, preferred = true, description = "The scrollbar's current value.") public void setValue(int value)
From source file:com.polivoto.vistas.Charts.java
private void crearTabla(Pregunta pregunta) { JScrollPane scrollPanel = new JScrollPane(); JPanel panel = new JPanel(new GridLayout(0, 1)); if (pregunta.obtenerCantidadDePerfiles() > 1) { for (int i = 0; i < pregunta.obtenerCantidadDePerfiles(); i++) { JPanel p = hacerTabla(pregunta, ((ResultadoPorPerfil) pregunta.obtenerResultadoPorPerfil(i)).getOpciones(), ((ResultadoPorPerfil) pregunta.obtenerResultadoPorPerfil(i)).getPerfil()); panel.add(p);/*from w ww.j av a 2 s . c o m*/ } } JPanel p = hacerTabla(pregunta, pregunta.obtenerOpciones(), "Todos"); panel.add(p); scrollPanel.setViewportView(panel); scrollPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); JScrollBar vertical = scrollPanel.getVerticalScrollBar(); vertical.setValue(0); vertical.setUnitIncrement(30); panelGrafica.add(scrollPanel, BorderLayout.CENTER); panel.repaint(); panel.revalidate(); panelGrafica.repaint(); panelGrafica.revalidate(); }
From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java
/** * Refreshes the waterfall display with the specified analysis data * @param Analyzed data from aro core./*from w w w . j a v a 2 s . com*/ */ public void refresh(AROTraceData aModel) { this.popup.refresh(null, 0); this.popup.setVisible(false); double range = DEFAULT_TIMELINE; // Create sorted list of request/response pairs List<WaterfallCategory> categoryList = new ArrayList<WaterfallCategory>(); if (aModel != null && aModel.getAnalyzerResult() != null) { this.traceDuration = aModel.getAnalyzerResult().getTraceresult().getTraceDuration(); // add 20% to make sure labels close to the right edge of the screen are visible this.traceDuration *= 1.2; range = Math.min(this.traceDuration, DEFAULT_TIMELINE); for (Session tcpSession : aModel.getAnalyzerResult().getSessionlist()) { Session thisSession = tcpSession; if (!tcpSession.isUDP()) { for (HttpRequestResponseInfo reqResInfo : tcpSession.getRequestResponseInfo()) { if (reqResInfo.getDirection() == HttpDirection.REQUEST && reqResInfo.getWaterfallInfos() != null) { categoryList.add(new WaterfallCategory(reqResInfo, thisSession)); } } } } // Sort and set index Collections.sort(categoryList); int index = 0; for (WaterfallCategory wCategory : categoryList) { wCategory.setIndex(++index); } } // Horizontal scroll bar used to scroll through trace duration JScrollBar hScrollBar = getHorizontalScroll(); hScrollBar.setMaximum((int) Math.ceil(this.traceDuration)); // Set the visible time range setTimeRange(0, range); CategoryAxis cAxis = getCategoryAxis(); cAxis.clearCategoryLabelToolTips(); // Build the dataset DefaultCategoryDataset underlying = new DefaultCategoryDataset(); for (WaterfallCategory wfc : categoryList) { RequestResponseTimeline rrTimeLine = wfc.getReqResp().getWaterfallInfos(); underlying.addValue(rrTimeLine.getStartTime(), Waterfall.BEFORE, wfc); underlying.addValue(rrTimeLine.getDnsLookupDuration(), Waterfall.DNS_LOOKUP, wfc); underlying.addValue(rrTimeLine.getInitialConnDuration(), Waterfall.INITIAL_CONNECTION, wfc); underlying.addValue(rrTimeLine.getSslNegotiationDuration(), Waterfall.SSL_NEGOTIATION, wfc); underlying.addValue(rrTimeLine.getRequestDuration(), Waterfall.REQUEST_TIME, wfc); underlying.addValue(rrTimeLine.getTimeToFirstByte(), Waterfall.TIME_TO_FIRST_BYTE, wfc); underlying.addValue(rrTimeLine.getContentDownloadDuration(), Waterfall.CONTENT_DOWNLOAD, wfc); underlying.addValue(null, Waterfall.HTTP_3XX_REDIRECTION, wfc); underlying.addValue(null, Waterfall.HTTP_4XX_CLIENTERROR, wfc); int code = wfc.getReqResp().getAssocReqResp().getStatusCode(); double endTime = this.traceDuration - rrTimeLine.getStartTime() - rrTimeLine.getTotalTime(); if (code >= 300 && code < 400) { underlying.addValue(endTime, Waterfall.AFTER_3XX, wfc); } else if (code >= 400) { underlying.addValue(endTime, Waterfall.AFTER_4XX, wfc); } else { underlying.addValue(endTime, Waterfall.AFTER, wfc); } cAxis.addCategoryLabelToolTip(wfc, wfc.getTooltip()); } // Vertical scroll bar is used to scroll through data JScrollBar vScrollBar = getVerticalScroll(); int count = underlying.getColumnCount(); vScrollBar.setValue(0); vScrollBar.setMaximum(count); vScrollBar.setVisibleAmount(count > 0 ? this.dataset.getMaximumCategoryCount() - 1 / count : 1); // Add the dataset to the plot CategoryPlot plot = getChartPanel().getChart().getCategoryPlot(); this.dataset = new SlidingCategoryDataset(underlying, 0, CATEGORY_MAX_COUNT); plot.setDataset(this.dataset); // Place proper colors on renderer for waterfall states final CategoryItemRenderer renderer = plot.getRenderer(); for (Object obj : underlying.getRowKeys()) { Waterfall wFall = (Waterfall) obj; int index = underlying.getRowIndex(wFall); Color paint; switch (wFall) { case DNS_LOOKUP: paint = dnsLoolupColor; break; case INITIAL_CONNECTION: paint = initiaConnColor; break; case SSL_NEGOTIATION: paint = sslNegColor; break; case REQUEST_TIME: paint = requestTimeColor; break; case TIME_TO_FIRST_BYTE: paint = firstByteTimeColor; break; case CONTENT_DOWNLOAD: paint = contentDownloadColor; break; case AFTER_3XX: paint = noneColor; renderer.setSeriesItemLabelPaint(index, threexColor); renderer.setSeriesVisibleInLegend(index, false); break; case AFTER_4XX: paint = noneColor; renderer.setSeriesItemLabelPaint(index, fourxColor); renderer.setSeriesVisibleInLegend(index, false); break; case HTTP_3XX_REDIRECTION: paint = threexColor; break; case HTTP_4XX_CLIENTERROR: paint = fourxColor; break; default: renderer.setSeriesItemLabelPaint(index, Color.black); renderer.setSeriesVisibleInLegend(index, false); paint = noneColor; } renderer.setSeriesPaint(index, paint); } // Adding the label at the end of bars renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() { private static final long serialVersionUID = 1L; @Override public String generateLabel(CategoryDataset dataset, int row, int column) { if (Waterfall.AFTER == dataset.getRowKey(row) || Waterfall.AFTER_3XX == dataset.getRowKey(row) || Waterfall.AFTER_4XX == dataset.getRowKey(row)) { WaterfallCategory waterfallItem = (WaterfallCategory) dataset.getColumnKey(column); RequestResponseTimeline waterfallInfos = waterfallItem.getReqResp().getWaterfallInfos(); DecimalFormat formatter = new DecimalFormat("#.##"); int code = waterfallItem.getReqResp().getAssocReqResp().getStatusCode(); return MessageFormat.format(ResourceBundleHelper.getMessageString("waterfall.totalTime"), formatter.format(waterfallInfos.getTotalTime()), code > 0 ? waterfallItem.getReqResp().getScheme() + " " + code : ResourceBundleHelper.getMessageString("waterfall.unknownCode")); } return null; } }); }
From source file:edu.brown.gui.CatalogViewer.java
/** * Scroll the attributes pane to the top */// w w w .j av a 2 s . c o m protected void scrollTextInfoToTop() { JScrollBar verticalScrollBar = this.textInfoScroller.getVerticalScrollBar(); JScrollBar horizontalScrollBar = this.textInfoScroller.getHorizontalScrollBar(); verticalScrollBar.setValue(verticalScrollBar.getMinimum()); horizontalScrollBar.setValue(horizontalScrollBar.getMinimum()); // System.err.println("VERTICAL=" + verticalScrollBar.getValue() + ", HORIZONTAL=" + horizontalScrollBar.getValue()); }
From source file:com.pingtel.sipviewer.SIPViewerFrame.java
protected void applyData(Vector vData) { m_model.clear();/* w ww. ja va2 s .c o m*/ if (m_sortBranchNodes) { // Do some magic to adjust for the case where the response // shows up just before the request. SipBranchData current = null; SipBranchData previous = null; String strCurrentBranchId; String strPreviousBranchId; for (int i = vData.size() - 1; i > 0; i--) { current = (SipBranchData) vData.elementAt(i); strCurrentBranchId = current.getThisBranchId(); previous = (SipBranchData) vData.elementAt(i - 1); strPreviousBranchId = current.getThisBranchId(); if ((strCurrentBranchId != null) && (strCurrentBranchId.length() > 0) && (strPreviousBranchId != null) && (strPreviousBranchId.length() > 0) && (strCurrentBranchId.equals(strPreviousBranchId)) && (current.isRequest()) && (!previous.isRequest()) && (current.getMethod() != "ack")) { vData.set(i, previous); vData.set(i - 1, current); System.out.println("Req/Resp swapped for branchID: " + strCurrentBranchId); } } } SipBranchData data = null; // loop over all the data elements and add them // to the model for (int i = 0; i < vData.size(); i++) { data = (SipBranchData) vData.elementAt(i); // pass in the for loop index since it is used // to set the displayIndex of each message, this // displayIndex is used to determine where the // message is displayed vertically and weather // it is visible or not (displayIndex of // -1 is invisible) addEntryToModel(data, i); } // Reset the scroll bar to the top. JScrollBar scroll = m_scrollPane.getVerticalScrollBar(); scroll.setValue(scroll.getMinimum()); // Revalidate to make sure the drawing pane is resized to match the // data. m_body.revalidate(); }
From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java
/** * Setting the time range for the graph. * @param low/*from w w w . j a v a 2s .c om*/ * @param high */ private void setTimeRange(double low, double high) { double lTime = low; double hTime = high; boolean zoomInEnabled = true; boolean zoomOutEnabled = true; JScrollBar scrollBarr = getHorizontalScroll(); if (hTime > traceDuration) { double delta = hTime - traceDuration; lTime = lTime - delta; hTime = hTime - delta; if (lTime < 0) { lTime = 0.0; } } if (hTime - lTime <= 1.0) { hTime = lTime + 1.0; zoomInEnabled = false; } if ((hTime - lTime) < traceDuration) { zoomOutEnabled = true; } else { zoomOutEnabled = false; } // logger.log(Level.FINE, "Range set to {0} - {1}", new Object[] {low, high}); scrollBarr.setValue((int) lTime); scrollBarr.setVisibleAmount((int) Math.ceil(hTime - lTime)); scrollBarr.setBlockIncrement(scrollBarr.getVisibleAmount()); // Enable zoom buttons appropriately zoomOutButton.setEnabled(zoomOutEnabled); zoomInButton.setEnabled(zoomInEnabled); }
From source file:me.mayo.telnetkek.MainPanel.java
private void writeToConsoleImmediately(final ConsoleMessage message, final boolean isTelnetError) { SwingUtilities.invokeLater(() -> { if (isTelnetError && chkIgnoreErrors.isSelected()) { return; }/*w w w. j a v a 2 s . c om*/ final StyledDocument styledDocument = mainOutput.getStyledDocument(); int startLength = styledDocument.getLength(); try { styledDocument.insertString(styledDocument.getLength(), message.getMessage() + System.lineSeparator(), StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, message.getColor())); } catch (BadLocationException ex) { throw new RuntimeException(ex); } if (MainPanel.this.chkAutoScroll.isSelected() && MainPanel.this.mainOutput.getSelectedText() == null) { final JScrollBar vScroll = mainOutputScoll.getVerticalScrollBar(); if (!vScroll.getValueIsAdjusting()) { if (vScroll.getValue() + vScroll.getModel().getExtent() >= (vScroll.getMaximum() - 50)) { MainPanel.this.mainOutput.setCaretPosition(startLength); final Timer timer = new Timer(10, (ActionEvent ae) -> { vScroll.setValue(vScroll.getMaximum()); }); timer.setRepeats(false); timer.start(); } } } }); }
From source file:org.datacleaner.widgets.result.DateGapAnalyzerResultSwingRenderer.java
@Override public JComponent render(DateGapAnalyzerResult result) { final TaskSeriesCollection dataset = new TaskSeriesCollection(); final Set<String> groupNames = result.getGroupNames(); final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION); final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS); final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS); for (final String groupName : groupNames) { final String groupDisplayName; if (groupName == null) { if (groupNames.size() == 1) { groupDisplayName = "All"; } else { groupDisplayName = LabelUtils.NULL_LABEL; }//from www.j a va 2 s . c o m } else { groupDisplayName = groupName; } final TimeInterval completeDuration = result.getCompleteDuration(groupName); final Task completeDurationTask = new Task(groupDisplayName, createTimePeriod(completeDuration.getFrom(), completeDuration.getTo())); completeDurationTaskSeries.add(completeDurationTask); // plot gaps { final SortedSet<TimeInterval> gaps = result.getGaps(groupName); int i = 1; Task rootTask = null; for (TimeInterval interval : gaps) { final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo()); if (rootTask == null) { rootTask = new Task(groupDisplayName, timePeriod); gapsTaskSeries.add(rootTask); } else { Task task = new Task(groupDisplayName + " gap" + i, timePeriod); rootTask.addSubtask(task); } i++; } } // plot overlaps { final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName); int i = 1; Task rootTask = null; for (TimeInterval interval : overlaps) { final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo()); if (rootTask == null) { rootTask = new Task(groupDisplayName, timePeriod); overlapsTaskSeries.add(rootTask); } else { Task task = new Task(groupDisplayName + " overlap" + i, timePeriod); rootTask.addSubtask(task); } i++; } } } dataset.add(overlapsTaskSeries); dataset.add(gapsTaskSeries); dataset.add(completeDurationTaskSeries); final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0, GROUPS_VISIBLE); final JFreeChart chart = ChartFactory.createGanttChart( "Date gaps and overlaps in " + result.getFromColumnName() + " / " + result.getToColumnName(), result.getGroupColumnName(), "Time", slidingDataset, true, true, false); ChartUtils.applyStyles(chart); // make sure the 3 timeline types have correct coloring { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDrawingSupplier(new DCDrawingSupplier(WidgetUtils.ADDITIONAL_COLOR_GREEN_BRIGHT, WidgetUtils.ADDITIONAL_COLOR_RED_BRIGHT, WidgetUtils.BG_COLOR_BLUE_BRIGHT)); } final int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size()); final ChartPanel chartPanel = ChartUtils.createPanel(chart, ChartUtils.WIDTH_WIDE, visibleLines * 50 + 200); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseMoved(ChartMouseEvent event) { Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); ChartEntity entity = event.getEntity(); if (entity instanceof PlotEntity) { cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); } chartPanel.setCursor(cursor); } @Override public void chartMouseClicked(ChartMouseEvent event) { // do nothing } }); final JComponent decoratedChartPanel; final StringBuilder chartDescription = new StringBuilder("<html>"); chartDescription.append("<p>The chart displays the recorded timeline based on FROM and TO dates.</p>"); chartDescription.append( "<p>The <b>red items</b> represent gaps in the timeline and the <b>green items</b> represent points in the timeline where more than one record show activity.</p>"); chartDescription.append( "<p>You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail.</p>"); if (groupNames.size() > GROUPS_VISIBLE) { final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL); scroll.setMinimum(0); scroll.setMaximum(groupNames.size()); scroll.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { int value = e.getAdjustable().getValue(); slidingDataset.setFirstCategoryIndex(value); } }); chartPanel.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int scrollType = e.getScrollType(); if (scrollType == MouseWheelEvent.WHEEL_UNIT_SCROLL) { int wheelRotation = e.getWheelRotation(); scroll.setValue(scroll.getValue() + wheelRotation); } } }); final DCPanel outerPanel = new DCPanel(); outerPanel.setLayout(new BorderLayout()); outerPanel.add(chartPanel, BorderLayout.CENTER); outerPanel.add(scroll, BorderLayout.EAST); chartDescription.append("<p>Use the right <b>scrollbar</b> to scroll up and down on the chart.</p>"); decoratedChartPanel = outerPanel; } else { decoratedChartPanel = chartPanel; } chartDescription.append("</html>"); final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString()); final DCPanel panel = new DCPanel(); panel.setLayout(new VerticalLayout()); panel.add(chartDescriptionLabel); panel.add(decoratedChartPanel); return panel; }
From source file:org.eobjects.datacleaner.widgets.result.DateGapAnalyzerResultSwingRenderer.java
@Override public JComponent render(DateGapAnalyzerResult result) { final TaskSeriesCollection dataset = new TaskSeriesCollection(); final Set<String> groupNames = result.getGroupNames(); final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION); final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS); final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS); for (final String groupName : groupNames) { final String groupDisplayName; if (groupName == null) { if (groupNames.size() == 1) { groupDisplayName = "All"; } else { groupDisplayName = LabelUtils.NULL_LABEL; }/*from ww w . jav a 2 s.c o m*/ } else { groupDisplayName = groupName; } final TimeInterval completeDuration = result.getCompleteDuration(groupName); final Task completeDurationTask = new Task(groupDisplayName, createTimePeriod(completeDuration.getFrom(), completeDuration.getTo())); completeDurationTaskSeries.add(completeDurationTask); // plot gaps { final SortedSet<TimeInterval> gaps = result.getGaps(groupName); int i = 1; Task rootTask = null; for (TimeInterval interval : gaps) { final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo()); if (rootTask == null) { rootTask = new Task(groupDisplayName, timePeriod); gapsTaskSeries.add(rootTask); } else { Task task = new Task(groupDisplayName + " gap" + i, timePeriod); rootTask.addSubtask(task); } i++; } } // plot overlaps { final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName); int i = 1; Task rootTask = null; for (TimeInterval interval : overlaps) { final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo()); if (rootTask == null) { rootTask = new Task(groupDisplayName, timePeriod); overlapsTaskSeries.add(rootTask); } else { Task task = new Task(groupDisplayName + " overlap" + i, timePeriod); rootTask.addSubtask(task); } i++; } } } dataset.add(overlapsTaskSeries); dataset.add(gapsTaskSeries); dataset.add(completeDurationTaskSeries); final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0, GROUPS_VISIBLE); final JFreeChart chart = ChartFactory.createGanttChart( "Date gaps and overlaps in " + result.getFromColumnName() + " / " + result.getToColumnName(), result.getGroupColumnName(), "Time", slidingDataset, true, true, false); ChartUtils.applyStyles(chart); // make sure the 3 timeline types have correct coloring { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDrawingSupplier(new DCDrawingSupplier(WidgetUtils.ADDITIONAL_COLOR_GREEN_BRIGHT, WidgetUtils.ADDITIONAL_COLOR_RED_BRIGHT, WidgetUtils.BG_COLOR_BLUE_BRIGHT)); } final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseMoved(ChartMouseEvent event) { Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); ChartEntity entity = event.getEntity(); if (entity instanceof PlotEntity) { cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); } chartPanel.setCursor(cursor); } @Override public void chartMouseClicked(ChartMouseEvent event) { // do nothing } }); final int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size()); chartPanel.setPreferredSize(new Dimension(0, visibleLines * 50 + 200)); final JComponent decoratedChartPanel; StringBuilder chartDescription = new StringBuilder(); chartDescription .append("<html><p>The chart displays the recorded timeline based on FROM and TO dates.<br/><br/>"); chartDescription.append( "The <b>red items</b> represent gaps in the timeline and the <b>green items</b> represent points in the timeline where more than one record show activity.<br/><br/>"); chartDescription.append( "You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail."); if (groupNames.size() > GROUPS_VISIBLE) { final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL); scroll.setMinimum(0); scroll.setMaximum(groupNames.size()); scroll.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { int value = e.getAdjustable().getValue(); slidingDataset.setFirstCategoryIndex(value); } }); chartPanel.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int scrollType = e.getScrollType(); if (scrollType == MouseWheelEvent.WHEEL_UNIT_SCROLL) { int wheelRotation = e.getWheelRotation(); scroll.setValue(scroll.getValue() + wheelRotation); } } }); final DCPanel outerPanel = new DCPanel(); outerPanel.setLayout(new BorderLayout()); outerPanel.add(chartPanel, BorderLayout.CENTER); outerPanel.add(scroll, BorderLayout.EAST); chartDescription.append("<br/><br/>Use the right <b>scrollbar</b> to scroll up and down on the chart."); decoratedChartPanel = outerPanel; } else { decoratedChartPanel = chartPanel; } chartDescription.append("</p></html>"); final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString()); chartDescriptionLabel.setBorder(new EmptyBorder(4, 10, 4, 10)); final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.add(decoratedChartPanel); split.add(chartDescriptionLabel); split.setDividerLocation(550); return split; }
From source file:GUI.GraphicalInterface.java
/** * Set scroll bar of {@code scrollPane} to extremum value. * <br> non-zero {@code value} means scroll to bottom. * <br> zero {@code value} means scroll to top. * * @param scrollPane {@code scrollPane} to be modified * @param value whether to scroll to top (zero) or bottom (non-zero) *///from w w w. jav a 2s . c o m private void setScrollBar(final javax.swing.JScrollPane scrollPane, final int value) { /* set the position of scroll bar */ javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (value == 0) { scrollPane.getVerticalScrollBar().setValue(0); } else { JScrollBar sb = scrollPane.getVerticalScrollBar(); sb.setValue(sb.getMaximum()); } } }); }
From source file:edu.purdue.cc.bionet.ui.GraphVisualizer.java
/** * Centers the graph in the display.// w ww . ja v a 2s. c o m */ public void center() { // toggle the scrollbars back and forth to center the image JScrollBar sb = scrollPane.getHorizontalScrollBar(); sb.setValue(sb.getMaximum()); sb.setValue(sb.getMinimum()); sb.setValue((sb.getMaximum() + sb.getMinimum()) / 2); sb = scrollPane.getVerticalScrollBar(); sb.setValue(sb.getMaximum()); sb.setValue(sb.getMinimum()); sb.setValue((sb.getMaximum() + sb.getMinimum()) / 2); }