List of utility methods to do JScrollPane
void | scrollToTop(final JScrollPane scrollPane) Scrolls scroll pane to the top left corner. JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar(); verticalScrollBar.setValue(verticalScrollBar.getMinimum()); horizontalScrollBar.setValue(horizontalScrollBar.getMinimum()); |
void | scrollToTop(JScrollPane scrollPane) scroll To Top final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
verticalScrollBar.setValue(verticalScrollBar.getMinimum());
|
void | scrollToTopLater(final JScrollPane scrollPane) Scrolls scroll pane to the top left corner a bit later. SwingUtilities.invokeLater(new Runnable() { public void run() { scrollToTop(scrollPane); }); |
void | scrollToVisible(Component comp, JScrollPane parent) Scrolls a component to the view position of a scrollpane if necessary Point p0 = parent.getViewport().getViewPosition();
Point p1 = comp.getLocation();
Rectangle r0 = parent.getViewport().getBounds();
Rectangle r1 = comp.getBounds();
if (p0.x > p1.x || p0.y > p1.y || (p0.x < p1.x && (p0.x + r0.width < p1.x + r1.width))
|| (p0.y < p1.y && (p0.y + r0.height < p1.y + r1.height)))
parent.getViewport().setViewPosition(comp.getBounds().getLocation());
|
void | setDefaultScrollbarUnits(JScrollPane scrollPane) Set reasonable unit increments for a scroll pane that does not contain a Scrollable. int unit = new JLabel().getFont().getSize() * 2; scrollPane.getHorizontalScrollBar().setUnitIncrement(unit); scrollPane.getVerticalScrollBar().setUnitIncrement(unit); |
void | setScrollpane(JScrollPane scrollpane) OS X shows scrollpanes even if there is no data to scroll. scrollpane.setHorizontalScrollBarPolicy(Integer.parseInt(System.getProperty("scrollbar.horizontal"))); scrollpane.setVerticalScrollBarPolicy(Integer.parseInt(System.getProperty("scrollbar.vertical"))); |
void | setScrollPaneSize(JScrollPane scrollPane, int rows, int columns) set Scroll Pane Size final Component view = scrollPane.getViewport().getView(); final FontMetrics fontMetrics = view.getFontMetrics(view.getFont()); final int width = fontMetrics.charWidth('m') * columns; scrollPane.setPreferredSize(new Dimension(width, fontMetrics.getHeight() * rows)); |
void | setUnitIncrement(JScrollPane scroller) set Unit Increment scroller.getVerticalScrollBar().setUnitIncrement(20); scroller.getHorizontalScrollBar().setUnitIncrement(20); |
JFrame | show(JComponent comp, String windowName, boolean hasScrollBars, int x, int y, int width, int height) show JFrame frame = new JFrame(windowName); frame.setLocation(x, y); if (hasScrollBars) { JScrollPane scroll = new JScrollPane(comp); frame.add(scroll, BorderLayout.CENTER); } else { frame.add(comp, BorderLayout.CENTER); frame.setSize(width, height); frame.setVisible(true); return frame; |
Point | toScrollPane(Component component, Point componentPoint, Point resultPoint) to Scroll Pane int px = componentPoint.x; int py = componentPoint.y; while (!(component instanceof JScrollPane)) { px += component.getX(); py += component.getY(); component = component.getParent(); if (resultPoint == null) { ... |