|
|
The JScrollPane class overrides the isOpaque method defined in the JComponent class. Recall that this method returns true if the component paints every pixel in its area. The JScrollPane class checks the opaque property of the component being scrolled in its viewport. Only if this property is true, and the component is at least as big as the viewport, does the JScrollPane class return true from the isOpaque method. Thus, the JScrollPane class is only opaque if the component being scrolled is opaque.
The border for a scroll pane can be set by using the standard setBorder method inherited from JComponent. This places a border around the center component as well as any scrollbars, headers, or corners that may be visible. If a border is desired around the viewport only, the setViewportBorder method can be used. This property is a bound property defined for the JScrollPane class. Clients listening for property change events will receive a change of the property name viewportBorder. The current state of this property is queried with the getViewportBorder method. This property, as well as the other bound properties introduced in the JScrollPane class, are presented in Table 15.1.
Table 15.1 Bound Properties Introduced by the JScrollPane Class
|
Property Name
| Setter Method
| Getter Method
|
|
VerticalScroll
| setVerticalScroll
| getVerticalScroll
|
BarPolicy
| BarPolicy
| BarPolicy
|
HorizontalScroll
| setHorizontalScroll
| getHorizontalScroll
|
BarPolicy
| BarPolicy
| BarPolicy
|
viewportBorder
| setViewportBorder
| getViewportBorder
|
horizontal\ScrollBar
| setHorizontalScrollBar
| getHorizontal ScrollBar
|
verticalScrollBar
| setVerticalScrollBar
| getVerticalScrollBar
|
viewport
| setViewport
| getViewport
|
rowHeader
| setRowHeader
| getRowHeader
|
columnHeader
| setColumnHeader
| getColumnHeader
|
LOWER_LEFT_CORNER
| setCorner
| getCorner
|
LOWER_RIGHT_CORNER
| setCorner
| getCorner
|
UPPER_LEFT_CORNER
| setCorner
| getCorner
|
UPPER_RIGHT_CORNER
| setCorner
| getCorner
|
|
The JScrollPane class overrides the isValidateRoot method defined in the JComponent class to return true. This means that child components that call the revalidate method will be validated. This eliminates the need to call invalidate followed immediately by validate, seen in many AWT-based applications. For a full discussion of the revalidate and isValidateRoot methods, see Chapter 3, JComponent.
ScrollPaneLayout Layout Manager
By default, the JScrollPane class uses an instance of the ScrollPaneLayout class, or one of its descendants, for its layout manager. This class manages the nine potential children of the scroll pane. These are the viewport in the center, the horizontal scrollbar on the bottom, the vertical scrollbar on the right, the column header on the top, the row header on the left, and the four corner components.
The ScrollPaneLayout class sizes the horizontal scrollbar and the column header to their preferred heights and to the width of the scroll pane, less the width of the row header and vertical scrollbar, if either is visible. Similarly, the vertical scrollbar and the row header are sized to their preferred widths and to the height of the scroll pane, less the height of the column header and horizontal scrollbar, if either is visible. The viewport is given the remainder of the scroll panes size, assuming there is space still available. The corner components are sized to the height and width of their adjacent components if they are visible. For example, the lower-right corner is the height of the horizontal scrollbar and the width of the vertical scrollbar if these components are visible. The corner component is not visible if its adjacent components are not visible. The ScrollPaneLayout class will size it to a width and height of zero, making it not visible.
|