Java Reference
In-Depth Information
The scrollMode property can be set to one of the class constants shown in Table 11-11.
In most cases, you can rely on the fastest and default BLIT_SCROLL_MODE mode.
Table 11-11. JViewport Scroll Modes
Scroll Mode
Description
BACKINGSTORE_SCROLL_MODE
A deprecated but supported mode that relies on a buffer
for scrolling
BLIT_SCROLL_MODE
The default mode, which relies on Graphics.copyArea()
SIMPLE_SCROLL_MODE
Redraws entire area
To move the visible part of the view around, just change the viewPosition property. This
moves the viewRect , allowing you to see a different part of the view. To demonstrate this, the
program shown in Listing 11-5 attaches keyboard accelerators to the JViewport so that you
can use the arrow keys to move around the view. (Normally, the JScrollPane would get these
keyboard actions.) The majority of the code is necessary to set up the appropriate input/action
maps. The boldfaced line of code is the one necessary to move the view.
Listing 11-5. Keyboard Movement Control in a JViewport
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MoveViewSample {
public static final int INCREASE = 0; // direction
public static final int DECREASE = 1; // direction
public static final int X_AXIS = 0; // axis
public static final int Y_AXIS = 1; // axis
public static final int UNIT = 0; // type
public static final int BLOCK = 1; // type
static class MoveAction extends AbstractAction {
JViewport viewport;
int direction;
int axis;
int type;
public MoveAction(JViewport viewport, int direction, int axis, int type) {
if (viewport == null) {
throw new IllegalArgumentException ("null viewport not permitted");
}
Search WWH ::




Custom Search