source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/ScrollableTable.java@ 11921

Last change on this file since 11921 was 11881, checked in by Don-vip, 7 years ago

findbugs - BC_UNCONFIRMED_CAST_OF_RETURN

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import java.awt.Container;
5import java.awt.Point;
6import java.awt.Rectangle;
7
8import javax.swing.JTable;
9import javax.swing.JViewport;
10import javax.swing.table.TableModel;
11
12/**
13 * Table offering easier scroll to a given row/column.
14 * @since 11881
15 */
16public class ScrollableTable extends JTable {
17
18 /**
19 * Constructs a <code>ScrollableTable</code> that is initialized with
20 * <code>dm</code> as the data model, a default column model,
21 * and a default selection model.
22 *
23 * @param dm the data model for the table
24 * @see #createDefaultColumnModel
25 * @see #createDefaultSelectionModel
26 */
27 public ScrollableTable(TableModel dm) {
28 super(dm);
29 }
30
31 /**
32 * Scrolls this table to make sure the (row,col) is visible.
33 * @param row row index
34 * @param col column index
35 */
36 public void scrollToVisible(int row, int col) {
37 Container parent = getParent();
38 if (parent instanceof JViewport) {
39 JViewport viewport = (JViewport) parent;
40 Rectangle rect = getCellRect(row, col, true);
41 Point pt = viewport.getViewPosition();
42 rect.setLocation(rect.x - pt.x, rect.y - pt.y);
43 viewport.scrollRectToVisible(rect);
44 }
45 }
46}
Note: See TracBrowser for help on using the repository browser.