Java Reference
In-Depth Information
public JScrollPane()
JScrollPane scrollPane = new JScrollPane();
public JScrollPane(Component view)
Icon icon = new ImageIcon("largeImage.jpg");
JLabel imageLabel = new JLabel(icon);
JScrollPane scrollPane = new JScrollPane(imageLabel);
public JScrollPane(int verticalScrollBarPolicy, int horizontalScrollBarPolicy)
JScrollPane scrollPane = new
JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
public JScrollPane(Component view, int verticalScrollBarPolicy,
int horizontalScrollBarPolicy)
JScrollPane scrollPane = new JScrollPane(imageLabel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
These offer the options of preinstalling a component to scroll and configuring the scrolling
policies of the individual scrollbars. By default, the scrollbars are shown only when needed.
Table 11-6 shows the JScrollPane constants used to explicitly set the policies for each scrollbar.
Using any other nonequivalent setting results in an IllegalArgumentException being thrown.
Table 11-6. JScrollPane Scrollbar Policies
Policy Type
Description
VERTICAL_SCROLLBAR_AS_NEEDED
Displays designated scrollbar if viewport is too small
to display its entire contents
HORIZONTAL_SCROLLBAR_AS_NEEDED
Displays designated scrollbar if viewport is too small
to display its entire contents
VERTICAL_SCROLLBAR_ALWAYS
Always displays designated scrollbar
HORIZONTAL_SCROLLBAR_ALWAYS
Always displays designated scrollbar
VERTICAL_SCROLLBAR_NEVER
Never displays designated scrollbar
HORIZONTAL_SCROLLBAR_NEVER
Never displays designated scrollbar
The next section explains how to add or change the component after creating a JScrollPane .
Search WWH ::




Custom Search