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:Main.java
/** * Move the cursor to the end of ScrollPane. * * @param pane the ScrollPane/*from w w w . j a va2 s. c o m*/ */ public static void moveEnd(JScrollPane pane) { JScrollBar bar = pane.getVerticalScrollBar(); bar.setValue(bar.getMaximum()); }
From source file:Main.java
/** * Scrolls the given component to its top or bottom. * Useful for implementing behavior like in Apple's Mail where home/end in the list cause scrolling in the text. *///www . j ava2 s . c om public static void scrollToExtremity(JComponent c, boolean top) { JScrollBar scrollBar = ((JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, c)) .getVerticalScrollBar(); scrollBar.setValue(top ? scrollBar.getMinimum() : scrollBar.getMaximum()); }
From source file:Main.java
/** * Scrolls scroll pane to the top left corner. *//*w w w . j a v a 2 s .c om*/ public static void scrollToTop(final JScrollPane scrollPane) { JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar(); verticalScrollBar.setValue(verticalScrollBar.getMinimum()); horizontalScrollBar.setValue(horizontalScrollBar.getMinimum()); }
From source file:Main.java
/** * Scrolls the given component by its unit or block increment in the given direction (actually a scale factor, so use +1 or -1). * Useful for implementing behavior like in Apple's Mail where page up/page down in the list cause scrolling in the text. *///from ww w .ja v a 2 s. c o m public static void scroll(JComponent c, boolean byBlock, int direction) { JScrollPane scrollPane = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, c); JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); int increment = byBlock ? scrollBar.getBlockIncrement(direction) : scrollBar.getUnitIncrement(direction); int newValue = scrollBar.getValue() + direction * increment; newValue = Math.min(newValue, scrollBar.getMaximum()); newValue = Math.max(newValue, scrollBar.getMinimum()); scrollBar.setValue(newValue); }
From source file:Main.java
public static 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(); }/* w w w.j ava 2s.c o m*/ scrollbar.setValue(newValue); }
From source file:ButtonCornerSample.java
public void actionPerformed(ActionEvent actionEvent) { JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar(); verticalScrollBar.setValue(verticalScrollBar.getMinimum()); horizontalScrollBar.setValue(horizontalScrollBar.getMinimum()); }
From source file:com.commander4j.util.JUtility.java
public static void scrolltoHomePosition(JScrollPane jScrollPane1) { JScrollBar verticalScrollBar = jScrollPane1.getVerticalScrollBar(); JScrollBar horizontalScrollBar = jScrollPane1.getHorizontalScrollBar(); verticalScrollBar.setValue(verticalScrollBar.getMinimum()); horizontalScrollBar.setValue(horizontalScrollBar.getMinimum()); }
From source file:EditorDropTarget4.java
public void autoscroll(Point location) { JScrollPane scroller = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, this); if (scroller != null) { JScrollBar hBar = scroller.getHorizontalScrollBar(); JScrollBar vBar = scroller.getVerticalScrollBar(); Rectangle r = getVisibleRect(); if (location.x <= r.x + scrollInsets.left) { // Need to scroll left hBar.setValue(hBar.getValue() - hBar.getUnitIncrement(-1)); }// www . j av a 2 s .c o m if (location.y <= r.y + scrollInsets.top) { // Need to scroll up vBar.setValue(vBar.getValue() - vBar.getUnitIncrement(-1)); } if (location.x >= r.x + r.width - scrollInsets.right) { // Need to scroll right hBar.setValue(hBar.getValue() + hBar.getUnitIncrement(1)); } if (location.y >= r.y + r.height - scrollInsets.bottom) { // Need to scroll down vBar.setValue(vBar.getValue() + vBar.getUnitIncrement(1)); } } }
From source file:ca.uhn.hl7v2.testpanel.ui.ActivityDetailsCellRenderer.java
@Override public Component getTableCellRendererComponent(final JTable theTable, Object theValue, boolean theIsSelected, boolean theHasFocus, final int theRow, int theColumn) { super.getTableCellRendererComponent(theTable, theValue, theIsSelected, theHasFocus, theRow, theColumn); if (theValue instanceof ActivityInfo) { renderInfo(theTable, theValue, theRow); } else if (theValue instanceof ActivityMessage) { renderMessage(theTable, theValue, theRow, theIsSelected); } else if (theValue instanceof ActivityBytesBase) { renderBytes(theTable, theValue, theRow); } else if (theValue instanceof ActivityValidationOutcome) { renderValidation(theTable, (ActivityValidationOutcome) theValue, theRow); }//from w ww .java 2 s .co m // int prefHeight = getPreferredSize().height; // prefHeight = Math.max(prefHeight, 10); // if (prefHeight != theTable.getRowHeight(theRow)) { // ourLog.trace("Setting height of row {} to {}", theRow, prefHeight); // theTable.setRowHeight(theRow, prefHeight); // } // EventQueue.invokeLater(new Runnable() { // public void run() { // int minWidth = getPreferredSize().width + 200; // // if (minWidth > theTable.getColumnModel().getColumn(2).getWidth()) { // theTable.getColumnModel().getColumn(2).setMinWidth(getPreferredSize().width); // theTable.getColumnModel().getColumn(2).setMaxWidth(getPreferredSize().width); // theTable.getColumnModel().getColumn(2).setPreferredWidth(getPreferredSize().width); // } // }}); // ourLog.info("Rendering row {}", theRow); // EventQueue.invokeLater(new Runnable() { // public void run() { // getTablePanel(). // JScrollBar vsb = myscrollPane.getVerticalScrollBar(); // vsb.setValue(vsb.getMaximum()); // ourLog.info("Setting scrollbar to bottom: {}", vsb.getMaximum()); // } // }); if (myScrollToBottom) { EventQueue.invokeLater(new Runnable() { public void run() { JScrollBar vsb = getTablePanel().getScrollPane().getVerticalScrollBar(); int newValue = vsb.getMaximum(); int existingValue = vsb.getValue(); if (newValue != existingValue) { vsb.setValue(newValue); ourLog.debug("Setting scrollbar to bottom, from {} to {}", existingValue, newValue); } if (theRow == getTablePanel().getTableModel().getRowCount() - 1) { myScrollToBottom = false; } } }); } return this; }
From source file:net.sf.jabref.gui.maintable.MainTable.java
public void scrollTo(int y) { JScrollBar scb = pane.getVerticalScrollBar(); scb.setValue(y * scb.getUnitIncrement(1)); }