|
58 | 58 |
|
59 | 59 | import javax.swing.AbstractButton; |
60 | 60 | import javax.swing.Action; |
| 61 | +import javax.swing.BoundedRangeModel; |
61 | 62 | import javax.swing.ImageIcon; |
62 | 63 | import javax.swing.InputMap; |
63 | 64 | import javax.swing.JButton; |
64 | 65 | import javax.swing.JComponent; |
65 | 66 | import javax.swing.JFrame; |
66 | 67 | import javax.swing.JMenuItem; |
67 | 68 | import javax.swing.JPopupMenu; |
| 69 | +import javax.swing.JScrollPane; |
| 70 | +import javax.swing.JViewport; |
68 | 71 | import javax.swing.KeyStroke; |
69 | 72 | import javax.swing.SwingUtilities; |
70 | 73 |
|
@@ -302,4 +305,22 @@ public static void dispatchToEDTWait(final Runnable runnable) { |
302 | 305 | runnable.run(); |
303 | 306 | } |
304 | 307 | } |
| 308 | + |
| 309 | + // -- Utility methods - scrolling -- |
| 310 | + |
| 311 | + /** Scrolls the given {@link JScrollPane} to its bottom left corner. */ |
| 312 | + public static void scrollToBottom(final JScrollPane scrollPane) { |
| 313 | + final JViewport viewport = scrollPane.getViewport(); |
| 314 | + viewport.setViewPosition(new Point(0, viewport.getView().getHeight())); |
| 315 | + } |
| 316 | + |
| 317 | + /** |
| 318 | + * Checks whether the given {@link JScrollPane} is currently scrolled to the |
| 319 | + * bottom of its view. |
| 320 | + */ |
| 321 | + public static boolean isScrolledToBottom(final JScrollPane scrollPane) { |
| 322 | + final BoundedRangeModel m = scrollPane.getVerticalScrollBar().getModel(); |
| 323 | + return m.getValue() + m.getExtent() >= m.getMaximum(); |
| 324 | + } |
| 325 | + |
305 | 326 | } |
0 commit comments