Java Reference
In-Depth Information
Note Some developers think of ScrollPaneLayout as a GridBagLayout with customized constraints
(and restricted contents). Under normal circumstances, most developers won't use ScrollPaneLayout
outside a JScrollPane .
Working with JScrollPane Headers and Corners
As Figure 11-15 and Table 11-8 demonstrate, many different regions exist within the JScrollPane .
Normally, you work with only the central view, and let the two scrollbars do their thing. In addition,
when working with the JTable component (described in Chapter 18), the table automatically
places the column labels within the column header region when placed within a JScrollPane .
You can also manually add or change the column header or row header for a JScrollPane .
Although you can completely replace the JViewport in these areas, it's easier to just set the
columnHeaderView or rowHeaderView property to the Component for the area. This action will
place the component within a JViewport for you.
To place a component in one of the corners of the JScrollPane , you need to call the
setCorner(String key, Component corner) method, where key is one of the following
constants from JScrollPane : LOWER_LEFT_CORNER , LOWER_RIGHT_CORNER , UPPER_LEFT_CORNER ,
or UPPER_RIGHT_CORNER .
Working with corners can be tricky. A corner component is displayed only if the two
components at a right angle from the corner are currently shown. For instance, suppose you
place a company logo within a label in the lower-right corner, and the scrollbar policy for both
scrollbars is to show only when necessary. In that case, if one scrollbar were not needed, the
logo in the corner wouldn't be shown. As another example, if a JScrollPane had a column
header showing but didn't have a row header, any component in the upper-left corner would
not be shown.
Therefore, just because you've set a corner to a component (as with scrollPane.setCorner
(JScrollPane.UPPER_LEFT_CORNER, logoLabel) ), don't expect it to be always or automatically
shown. Moreover, as Figure 11-16 shows, the neighboring areas control the size of the corner.
Don't assume a corner component can be as large as necessary. That's because its minimum,
preferred, and maximum sizes are completely ignored. In Figure 11-16, the actual image used
to create the corner component is larger than the space used.
Figure 11-16. A JScrollPane with a corner component and row and column headers
Note Changing a corner of a JScrollPane acts like a bound property where the property name is one of
the corner keys shown in Table 11-8.
 
Search WWH ::




Custom Search