@Override public void run() { JScrollBar verticalScrollbar = scrollPane.getVerticalScrollBar(); if (verticalScrollbar == null) return; int scrollMax = verticalScrollbar.getMaximum() - verticalScrollbar.getMinimum(); long newScrollValue = Math.round(position * scrollMax) + verticalScrollbar.getMinimum(); if (newScrollValue < verticalScrollbar.getMinimum()) newScrollValue = verticalScrollbar.getMinimum(); if (newScrollValue > verticalScrollbar.getMaximum()) newScrollValue = verticalScrollbar.getMaximum(); verticalScrollbar.setValue((int) newScrollValue); } });
@Override public void adjustmentValueChanged(AdjustmentEvent e) { String content = textArea.getText(); if (content == null || content.length() == 0) return; int scrollValue = verticalScrollbar.getValue() - verticalScrollbar.getMinimum(); int scrollMax = verticalScrollbar.getMaximum() - verticalScrollbar.getMinimum(); if (scrollMax < 1 || scrollValue < 0 || scrollValue > scrollMax) return; lastScrollPercent = (((double) scrollValue) / ((double) scrollMax)); } });
private void showMatchedPart(int idx) { Point2D.Double coord = matchedPartCoordinates.get(idx); Dimension treeSize = tjp.getPreferredSize(); JScrollBar horizontal = scroller.getHorizontalScrollBar(); JScrollBar vertical = scroller.getVerticalScrollBar(); int horizontalLength = horizontal.getMaximum() - horizontal.getMinimum(); double x = Math.max(0, (coord.getX() / treeSize.getWidth() * horizontalLength - (scroller.getWidth() / 2.0))); int verticalLength = vertical.getMaximum() - vertical.getMinimum(); double y = Math.max(0, (coord.getY() / treeSize.getHeight() * verticalLength - (scroller.getHeight() / 2.0))); horizontal.setValue((int) x); vertical.setValue((int) y); }
int startingX = viewRect.x; boolean leftToRight = comp.getComponentOrientation().isLeftToRight(); int scrollMin = toScroll.getMinimum(); int scrollMax = toScroll.getMaximum() - toScroll.getModel().getExtent(); newValue = toScroll.getMaximum(); } else if (delta < 0 && newValue > oldValue) { newValue = toScroll.getMinimum(); newValue = toScroll.getMaximum(); } else if (delta < 0 && newValue > oldValue) { newValue = toScroll.getMinimum();
@Override public Integer call() throws Exception { return bar.getMinimum(); } }));
/** * Scrolls scroll pane to the top left corner. */ public static void scrollToTop(final JScrollPane scrollPane) { JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar(); verticalScrollBar.setValue(verticalScrollBar.getMinimum()); horizontalScrollBar.setValue(horizontalScrollBar.getMinimum()); }
public void focusLost(FocusEvent evt) { JScrollBar currentBar = ((JScrollBar)sp.scrollers.get(index)); currentBar.setValue((int)Math.floor(currentBar.getMinimum())); int newVisibleAmount = (int)Double.parseDouble(((JTextField)this.sp.granularity.get(index)).getText()); if (newVisibleAmount > Math.ceil(currentBar.getMaximum()) - Math.floor(currentBar.getMinimum())) newVisibleAmount = (int)(Math.ceil(currentBar.getMaximum()) - Math.floor(currentBar.getMinimum())); currentBar.setVisibleAmount(newVisibleAmount); ((JLabel)sp.slideLabels.get(index)).setText("Viewing Range: [" + currentBar.getValue() + ", " + (currentBar.getValue() + currentBar.getVisibleAmount()) + "]"); } }
@RunsInCurrentThread private int maximumMinusMinimum(@Nonnull JScrollBar scrollBar) { return scrollBar.getMaximum() - scrollBar.getMinimum(); }
private void calculateButtonsEnabled() { float extent = scrollbar.getVisibleAmount(); float range = scrollbar.getMaximum() - scrollbar.getMinimum(); buttonsEnabled = (range > extent); }
@RunsInCurrentThread private static void checkPositionInBounds(@Nonnull JScrollBar scrollBar, int position) { int min = scrollBar.getMinimum(); int max = scrollBar.getMaximum(); if (position >= min && position <= max) { return; } throw new IllegalArgumentException(concat("Position <", position, "> is not within the JScrollBar bounds of <", min, "> and <", max, ">")); }
@Override protected Pair<Integer, GenericRange<Point>> executeInEDT() { checkEnabledAndShowing(scrollBar); int position = scrollBar.getMinimum(); GenericRange<Point> scrollInfo = scrollInfo(scrollBar, location, position); return Pair.of(position, scrollInfo); } });
@Override public void focusGained(FocusEvent fe) { if (-1 == table.getSelectedRow() && table.getRowCount() > 0) { table.setRowSelectionInterval(0,0); JScrollBar scrollbar = scrollpane.getVerticalScrollBar(); scrollbar.setValue(scrollbar.getMinimum()); } if (-1 == table.getSelectedColumn()) { table.setColumnSelectionInterval(0,0); } } } //}}}
/** * @param msg */ public void updateOB(OrderBookMessage msg) { log.info("OrderBookView.updateOrderBook"); OrderBookModel model = ((OrderBookModel) tables.get(msg.getSide() + "_" + msg.getProduct_id()).getModel()); model.incomingOrder(msg); JScrollBar bidVerticalScrollBar = scrollPanes.get("buy_" + msg.getProduct_id()).getVerticalScrollBar(); JScrollBar askVerticalScrollBar = scrollPanes.get("sell_" + msg.getProduct_id()).getVerticalScrollBar(); askVerticalScrollBar.setValue(askVerticalScrollBar.getMaximum()); bidVerticalScrollBar.setValue(bidVerticalScrollBar.getMinimum()); }
@Override public void focusGained(FocusEvent fe) { if (-1 == table.getSelectedRow()) { table.setRowSelectionInterval(0,0); JScrollBar scrollbar = scrollpane.getVerticalScrollBar(); scrollbar.setValue(scrollbar.getMinimum()); } if (-1 == table.getSelectedColumn()) { table.setColumnSelectionInterval(0,0); } } } //}}}
private void showMatchedPart(int idx) { Point2D.Double coord = matchedPartCoordinates.get(idx); Dimension treeSize = tjp.getPreferredSize(); JScrollBar horizontal = scroller.getHorizontalScrollBar(); JScrollBar vertical = scroller.getVerticalScrollBar(); int horizontalLength = horizontal.getMaximum() - horizontal.getMinimum(); double x = Math.max(0, (coord.getX() / treeSize.getWidth() * horizontalLength - (scroller.getWidth() / 2.0))); int verticalLength = vertical.getMaximum() - vertical.getMinimum(); double y = Math.max(0, (coord.getY() / treeSize.getHeight() * verticalLength - (scroller.getHeight() / 2.0))); horizontal.setValue((int) x); vertical.setValue((int) y); }
/** * Move the view (by setting the scrollbar value), according to the given mouse coordinate * within the NaviView component. */ private void moveView(int ypos) { int modelPos = yViewToDocument(ypos - dragOffset); int lineNum = getDocument().getDefaultRootElement().getElementIndex(modelPos); lineNum = Math.max(0, lineNum); int totalLines = getDocument().getDefaultRootElement().getElementCount(); int totalAmt = scrollBar.getMaximum() - scrollBar.getMinimum(); int pos = lineNum * totalAmt / totalLines + scrollBar.getMinimum(); scrollBar.setValue(pos); }
void scrollByBlock(JScrollBar scrollbar, int direction) { // This method is called from BasicScrollPaneUI to implement wheel // scrolling, and also from scrollByBlock(). int oldValue = scrollbar.getValue(); int blockIncrement = scrollbar.getBlockIncrement(direction); int delta = blockIncrement * ((direction > 0) ? +1 : -1); int newValue = oldValue + delta; // Check for overflow. if (delta > 0 && newValue < oldValue) { newValue = scrollbar.getMaximum(); } else if (delta < 0 && newValue > oldValue) { newValue = scrollbar.getMinimum(); } scrollbar.setValue(newValue); }
private static void scroll(final JScrollBar scroller, final MouseWheelEvent event) { if (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { int unitsToScroll = event.getUnitsToScroll(); int direction = unitsToScroll < 0 ? -1 : 1; if (unitsToScroll != 0) { int increment = scroller.getUnitIncrement(direction); int oldValue = scroller.getValue(); int newValue = oldValue + increment * unitsToScroll; newValue = Math.max(Math.min(newValue, scroller.getMaximum() - scroller.getVisibleAmount()), scroller.getMinimum()); if (oldValue != newValue) scroller.setValue(newValue); } event.consume(); } }
public void adjustmentValueChanged(AdjustmentEvent e) { JScrollBar rSB = rightScrollPane.getVerticalScrollBar(); verticalScrollBar.removeAdjustmentListener(verticalScrollBarAdjustementListener); verticalScrollBar.setMinimum(rSB.getMinimum()); verticalScrollBar.setMaximum(rSB.getMaximum()); verticalScrollBar.setBlockIncrement(rSB.getBlockIncrement()); verticalScrollBar.setUnitIncrement(rSB.getUnitIncrement()); verticalScrollBar.setVisibleAmount(rSB.getVisibleAmount()); verticalScrollBar.addAdjustmentListener(verticalScrollBarAdjustementListener); } }
void zoomInY( final float factor ) { final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar(); final TreePanel treepanel = getMainPanel().getCurrentTreePanel(); treepanel.multiplyUrtFactor( 1.1f ); final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) ); treepanel.setYdistance( ( treepanel.getYdistance() * factor ) ); getMainPanel().adjustJScrollPane(); treepanel.resetPreferredSize(); getMainPanel().getCurrentScrollPane().getViewport().validate(); sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x ) - ( sb.getVisibleAmount() / 2.0 ) ) ); treepanel.resetPreferredSize(); treepanel.updateOvSizes(); }