Java Reference
In-Depth Information
Figure 18-3. JTable without a JScrollPane
Therefore, every table you create needs to be placed within a JScrollPane by using code
similar to the following:
JTable table = new JTable(...);
JScrollPane scrollPane = new JScrollPane(table);
Manually Positioning the JTable View
When a JTable within a JScrollPane is added to a window, the table will automatically appear
with the table positioned so that the first row and column appear in the upper-left corner. If
you ever need to return the position to the origin, you can set the viewport position back to
point (0, 0).
scrollPane.getViewport().setViewPosition(new Point(0,0));
For scrolling purposes, the block increment amount is the visible width and height of the
viewport, depending on the direction of the scrollbar. The unit increment is 100 pixels for hori-
zontal scrolling and the height of a single row for vertical scrolling. See Figure 18-4 for a visual
representation of these increments.
5NIT)NCREMENT
PIXELS
5NIT)NCREMENT
"LOCK)NCREMENT
"LOCK)NCREMENT
Figure 18-4. JTable scrolling increments
Search WWH ::




Custom Search