List of utility methods to do JScrollPane
boolean | isScrolledToBottom(final JScrollPane scrollPane) Checks whether the given JScrollPane is currently scrolled to the bottom of its view. final BoundedRangeModel m = scrollPane.getVerticalScrollBar().getModel(); return m.getValue() + m.getExtent() >= m.getMaximum(); |
void | makeComponentDragScrollable(final JComponent component) Makes a component drag-scrollable. final MouseAdapter dragHandler = new MouseAdapter() { int dragStartX, dragStartY; @Override public void mousePressed(final MouseEvent event) { if ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { dragStartX = event.getXOnScreen(); dragStartY = event.getYOnScreen(); }; @Override public void mouseDragged(final MouseEvent event) { if ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { final Rectangle visibleRect = component.getVisibleRect(); visibleRect.x += (dragStartX - event.getXOnScreen()) * 2; visibleRect.y += (dragStartY - event.getYOnScreen()) * 2; component.scrollRectToVisible(visibleRect); dragStartX = event.getXOnScreen(); dragStartY = event.getYOnScreen(); }; component.addMouseListener(dragHandler); component.addMouseMotionListener(dragHandler); component.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); |
JScrollPane | makeListInScrollPane(Collection make List In Scroll Pane return makeListInScrollPane(items, namer, DEFAULT_MAX_VIEW);
|
JScrollPane | makeVScroller(Component c) make V Scroller return new JScrollPane(c, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
void | moveEnd(JScrollPane pane) Move the cursor to the end of ScrollPane. JScrollBar bar = pane.getVerticalScrollBar(); bar.setValue(bar.getMaximum()); |
JScrollPane | newJScrollPane(String title, Component c) new J Scroll Pane JScrollPane sp = new JScrollPane(c); sp.setBorder(BorderFactory.createTitledBorder(title)); return sp; |
void | resetScrollPane(final JScrollPane scrollPane) Resets the scroll pane to 0,0. SwingUtilities.invokeLater(() -> { scrollPane.getHorizontalScrollBar().setValue(0); scrollPane.getVerticalScrollBar().setValue(0); }); |
void | scrollToBottom(final JScrollPane scrollPane) Scrolls the given JScrollPane to its bottom left corner. final JViewport viewport = scrollPane.getViewport(); viewport.setViewPosition(new Point(0, viewport.getView().getHeight())); |
void | scrolltoHomePosition(JScrollPane jScrollPane1) scrollto Home Position JScrollBar verticalScrollBar = jScrollPane1.getVerticalScrollBar(); JScrollBar horizontalScrollBar = jScrollPane1.getHorizontalScrollBar(); verticalScrollBar.setValue(verticalScrollBar.getMinimum()); horizontalScrollBar.setValue(horizontalScrollBar.getMinimum()); |
void | scrollToTop(final JScrollPane scroller, int delay) scroll To Top SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JViewport viewport = scroller.getViewport(); JComponent comp = (JComponent) viewport.getView(); if (comp instanceof JTextPane) { JTextPane textPane = (JTextPane) comp; textPane.setCaretPosition(0); ... |