java.awt.event

Class MouseWheelEvent

Implemented Interfaces:
Serializable

public class MouseWheelEvent
extends MouseEvent

This event is generated for a mouse wheel rotation. The wheel (the middle mouse button on most modern mice) can be rotated towards or away from the user, and is often used for scrolling.

Because of the special use for scrolling components, MouseWheelEvents often affect a different component than the one located at the point of the event. If the component under the mouse cursor does not accept wheel events, the event is passed to the first ancestor container which does. This is often a ScrollPane, which knows how to scroll. If an AWT component is built from a native widget that knows how to use mouse wheel events, that component will consume the event.

The two most common scroll types are "units" (lines at a time) or "blocks" (pages at a time). The initial setting is taken from the platform, although the user can adjust the setting at any time.

Since:
1.4
See Also:
MouseWheelListener, ScrollPane, ScrollPane.setWheelScrollingEnabled(boolean), JScrollPane, JScrollPane.setWheelScrollingEnabled(boolean), Serialized Form

Field Summary

static int
WHEEL_BLOCK_SCROLL
Indicates scrolling by blocks (pages).
static int
WHEEL_UNIT_SCROLL
Indicates scrolling by units (lines).

Fields inherited from class java.awt.event.MouseEvent

BUTTON1, BUTTON2, BUTTON3, MOUSE_CLICKED, MOUSE_DRAGGED, MOUSE_ENTERED, MOUSE_EXITED, MOUSE_FIRST, MOUSE_LAST, MOUSE_MOVED, MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_WHEEL, NOBUTTON

Fields inherited from class java.awt.event.InputEvent

ALT_DOWN_MASK, ALT_GRAPH_DOWN_MASK, ALT_GRAPH_MASK, ALT_MASK, BUTTON1_DOWN_MASK, BUTTON1_MASK, BUTTON2_DOWN_MASK, BUTTON2_MASK, BUTTON3_DOWN_MASK, BUTTON3_MASK, CTRL_DOWN_MASK, CTRL_MASK, META_DOWN_MASK, META_MASK, SHIFT_DOWN_MASK, SHIFT_MASK

Fields inherited from class java.awt.event.ComponentEvent

COMPONENT_FIRST, COMPONENT_HIDDEN, COMPONENT_LAST, COMPONENT_MOVED, COMPONENT_RESIZED, COMPONENT_SHOWN

Fields inherited from class java.awt.AWTEvent

ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK, consumed, id

Fields inherited from class java.util.EventObject

source

Constructor Summary

MouseWheelEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger, int scrollType, int scrollAmount, int wheelRotation)
Initializes a new instance of MouseWheelEvent with the specified information.

Method Summary

int
getScrollAmount()
Returns the number of units to scroll in response to this event.
int
getScrollType()
This method returns the scrolling pattern this event requests.
int
getUnitsToScroll()
This is a convenience method which aids in a common listener for scrolling a scrollpane (although this is already built into ScrollPane and JScrollPane).
int
getWheelRotation()
Gets the number of "clicks" the wheel was rotated.
String
paramString()
Returns a string identifying this event.

Methods inherited from class java.awt.event.MouseEvent

getButton, getClickCount, getLocationOnScreen, getMouseModifiersText, getPoint, getX, getXOnScreen, getY, getYOnScreen, isPopupTrigger, paramString, translatePoint

Methods inherited from class java.awt.event.InputEvent

consume, getModifiers, getModifiersEx, getModifiersExText, getWhen, isAltDown, isAltGraphDown, isConsumed, isControlDown, isMetaDown, isShiftDown

Methods inherited from class java.awt.event.ComponentEvent

getComponent, paramString

Methods inherited from class java.awt.AWTEvent

consume, getID, isConsumed, paramString, setSource, toString

Methods inherited from class java.util.EventObject

getSource, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

WHEEL_BLOCK_SCROLL

public static final int WHEEL_BLOCK_SCROLL
Indicates scrolling by blocks (pages).
Field Value:
1

WHEEL_UNIT_SCROLL

public static final int WHEEL_UNIT_SCROLL
Indicates scrolling by units (lines).
Field Value:
0

Constructor Details

MouseWheelEvent

public MouseWheelEvent(Component source,
                       int id,
                       long when,
                       int modifiers,
                       int x,
                       int y,
                       int clickCount,
                       boolean popupTrigger,
                       int scrollType,
                       int scrollAmount,
                       int wheelRotation)
Initializes a new instance of MouseWheelEvent with the specified information. Note that an invalid id leads to unspecified results.
Parameters:
source - the source of the event
id - the event id
when - the timestamp of when the event occurred
modifiers - any modifier bits for this event
x - the X coordinate of the mouse point
y - the Y coordinate of the mouse point
clickCount - the number of mouse clicks for this event
popupTrigger - true if this event triggers a popup menu
scrollType - one of WHEEL_UNIT_SCROLL, WHEEL_BLOCK_SCROLL
scrollAmount - the number of units to scroll, ignored for block type
wheelRotation - the number of rotation "clicks"
Throws:
IllegalArgumentException - if source is null

Method Details

getScrollAmount

public int getScrollAmount()
Returns the number of units to scroll in response to this event. This only makes sense when the scroll type is WHEEL_UNIT_SCROLL.
Returns:
the number of scroll units, if defined

getScrollType

public int getScrollType()
This method returns the scrolling pattern this event requests. Legal values are WHEEL_UNIT_SCROLL and WHEEL_BLOCK_SCROLL.
Returns:
the scroll type

getUnitsToScroll

public int getUnitsToScroll()
This is a convenience method which aids in a common listener for scrolling a scrollpane (although this is already built into ScrollPane and JScrollPane). This method only makes sense when getScrollType() returns WHEEL_UNIT_SCROLL.

This accounts for direction of scroll and amount of wheel movement, as interpreted by the platform settings.

Returns:
the number of units to scroll

getWheelRotation

public int getWheelRotation()
Gets the number of "clicks" the wheel was rotated. Negative values move up (away) from the user, positive values move down (towards) the user.
Returns:
the number of rotation clicks

paramString

public String paramString()
Returns a string identifying this event. For mouse wheel events, this is super.paramString() + ",scrollType=WHEEL_" + (getScrollType() == WHEEL_UNIT_SCROLL ? "UNIT" : "BLOCK") + "_SCROLL,scrollAmount=" + getScrollAmount() + ",wheelRotation=" + getWheelRotation().
Overrides:
paramString in interface MouseEvent
Returns:
a string identifying this event

MouseWheelEvent.java -- a mouse wheel event Copyright (C) 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.