List of utility methods to do JScrollPane Scroll
void | scrollComponentTo(JComponent c, Rectangle r) Scroll a component contained in a JScrollPane to its end int extraHeight = 40; Rectangle rr = new Rectangle(r.x, r.y - extraHeight, r.width, 2 * extraHeight + r.height); Rectangle rrr = rr.intersection(c.getBounds()); if (rrr.height > 0) c.scrollRectToVisible(rrr); |
void | scrollComponentToEnd(JComponent c) Scroll a component contained in a JScrollPane to its end Rectangle r = c.getBounds();
scrollComponentTo(c, new Rectangle(0, r.height - 2, r.width, 2));
|
JScrollPane | scrolleable(final JComponent comp) scrolleable final JScrollPane scroll = new JScrollPane(); if (comp != null) { scroll.setViewportView(comp); scroll.setOpaque(false); scroll.getViewport().setOpaque(false); return scroll; |
JComponent | scrollH(JComponent content) scroll H JScrollPane scroll = new JScrollPane(content); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); return scroll; |
void | scrollRectLater(final JComponent comp, final Rectangle r) scroll Rect Later SwingUtilities.invokeLater(new Runnable() { public void run() { comp.scrollRectToVisible(r); }); |
void | scrollRectToVisible(Component component, Rectangle aRect) scroll Rect To Visible Container parent; int dx = component.getX(), dy = component.getY(); for (parent = component.getParent(); parent != null && (!(parent instanceof JViewport) || (((JViewport) parent) .getClientProperty("HierarchicalTable.mainViewport") == null)); parent = parent .getParent()) { Rectangle bounds = parent.getBounds(); dx += bounds.x; ... |
void | scrollToComponent(Component cmp) scroll To Component Container parent = cmp.getParent(); while (parent != null) { if (parent instanceof JScrollPane) { JScrollPane pane = (JScrollPane) parent; Point location = getRelativeLocation(pane.getViewport().getView(), cmp); Rectangle bounds = cmp.getBounds(); bounds.setLocation(location); pane.getViewport().scrollRectToVisible(bounds); ... |
void | scrollToVisible(int row, int col) Assumes table is contained in a JScrollPane. scrollToVisible(getJTable(), row, col); |
JComponent | scrollV(String title, JComponent content) scroll V JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createTitledBorder(title)); JScrollPane scroll = new JScrollPane(content); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); p.add(scroll); return p; |
void | scrollVertically(JComponent c, Rectangle r) scroll Vertically scrollVertically(c, r.y, r.y + r.height); |