Java Utililty Methods JScrollPane

List of utility methods to do JScrollPane

Description

The list of methods to do JScrollPane are organized into topic(s).

Method

booleanisScrolledToBottom(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();
voidmakeComponentDragScrollable(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));
JScrollPanemakeListInScrollPane(Collection items, Function namer)
make List In Scroll Pane
return makeListInScrollPane(items, namer, DEFAULT_MAX_VIEW);
JScrollPanemakeVScroller(Component c)
make V Scroller
return new JScrollPane(c, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
voidmoveEnd(JScrollPane pane)
Move the cursor to the end of ScrollPane.
JScrollBar bar = pane.getVerticalScrollBar();
bar.setValue(bar.getMaximum());
JScrollPanenewJScrollPane(String title, Component c)
new J Scroll Pane
JScrollPane sp = new JScrollPane(c);
sp.setBorder(BorderFactory.createTitledBorder(title));
return sp;
voidresetScrollPane(final JScrollPane scrollPane)
Resets the scroll pane to 0,0.
SwingUtilities.invokeLater(() -> {
    scrollPane.getHorizontalScrollBar().setValue(0);
    scrollPane.getVerticalScrollBar().setValue(0);
});
voidscrollToBottom(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()));
voidscrolltoHomePosition(JScrollPane jScrollPane1)
scrollto Home Position
JScrollBar verticalScrollBar = jScrollPane1.getVerticalScrollBar();
JScrollBar horizontalScrollBar = jScrollPane1.getHorizontalScrollBar();
verticalScrollBar.setValue(verticalScrollBar.getMinimum());
horizontalScrollBar.setValue(horizontalScrollBar.getMinimum());
voidscrollToTop(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);
...