|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Canvas | +--com.jthomas.util.ImageLabel | +--com.jthomas.util.ImageButton
A button class that uses an image instead of a textual label. Unlike many of the ImageButton classes available, it triggers an ACTION_EVENT, so you can add behavior in the same two ways as you can with normal Buttons:
By default, with FlowLayout the ImageButton takes its minimum size (just enclosing the image). The default with BorderLayout is to expand to fill the region in width (North/South), height (East/West) or both (Center). This is the same behavior as the builtin Button class. If you give an explicit resize or reshape call before adding the ImageButton to the Container, this size will override the defaults.
The original of the source code can be found at http://www.apl.jhu.edu/~hall/java/ImageLabel/ImageButton.java, the documentation is at .../ImageButton.html, and a small example program can be found at .../ImageButtonTest.html.
No warranty of any kind is provided. Permission is granted to use and/or modify for any purpose.
7/96 Marty Hall:
Icon
,
GrayFilter
,
Serialized FormNested Class Summary |
Nested classes inherited from class java.awt.Canvas |
java.awt.Canvas.AccessibleAWTCanvas |
Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
int |
darkness
An int whose bits are combined via "and" ("&") with the alpha, red, green, and blue bits of the pixels of the image to produce the grayed-out image to use when button is depressed. |
protected static java.awt.Color |
defaultBorderColor
Default color of 3D border around image. |
protected static int |
defaultBorderWidth
Default width of 3D border around image. |
protected java.awt.Image |
grayImage
Gray image created automatically from regular image via an image filter to use when button is depressed. |
Fields inherited from class com.jthomas.util.ImageLabel |
debug, defaultImageString, explicitSize, height, image, imageString, margin, marginColor, width |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
ImageButton()
Create an ImageButton with the default image. |
|
ImageButton(java.awt.Image image)
Create an ImageButton using the image specified. |
|
ImageButton(java.lang.String imageURLString)
Create an ImageButton using the image at URL specified by the string. |
|
ImageButton(java.net.URL imageURL)
Create an ImageButton using the image at URL specified. |
Method Summary | |
boolean |
action(java.awt.Event event,
java.lang.Object arg)
Generated when the button is clicked and released. |
java.awt.Color |
getBorderColor()
Returns the Color for the border around the outside of the image. |
int |
getBorderWidth()
Returns the width around the outside of the image. |
boolean |
mouseDown(java.awt.Event event,
int x,
int y)
When the mouse is clicked, reverse the 3D border and draw a dark-gray version of the image. |
boolean |
mouseExit(java.awt.Event event,
int x,
int y)
If you move the mouse off the button while the mouse is down, abort and do NOT trigger the action. |
boolean |
mouseUp(java.awt.Event event,
int x,
int y)
If cursor is still inside, trigger the action event and redraw the image (non-gray, button "out"). |
void |
paint(java.awt.Graphics g)
Draws the image with the border around it. |
void |
setBorderColor(java.awt.Color borderColor)
Sets the Color for the border around the outside of the image. |
void |
setBorderWidth(int borderWidth)
Sets the width around the outside of the image. |
Methods inherited from class com.jthomas.util.ImageLabel |
centerAt, contains, debug, drawRect, getMinimumSize, getPreferredSize, setBounds, setSize, waitForImage |
Methods inherited from class java.awt.Canvas |
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update |
Methods inherited from class java.awt.Component |
add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDrag, mouseEnter, mouseMove, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static final int defaultBorderWidth
setBorderWidth(int)
,
getBorderWidth()
,
Constant Field Valuesprotected static final java.awt.Color defaultBorderColor
setBorderColor(java.awt.Color)
,
getBorderColor()
protected java.awt.Image grayImage
public int darkness
Constructor Detail |
public ImageButton()
ImageLabel.defaultImageString
public ImageButton(java.lang.String imageURLString)
imageURLString
- A String specifying the URL of the image.public ImageButton(java.net.URL imageURL)
imageURL
- The URL of the image.public ImageButton(java.awt.Image image)
image
- The image.Method Detail |
public void setBorderWidth(int borderWidth)
getBorderWidth()
public int getBorderWidth()
setBorderWidth(int)
public void setBorderColor(java.awt.Color borderColor)
getBorderColor()
public java.awt.Color getBorderColor()
setBorderColor(java.awt.Color)
public void paint(java.awt.Graphics g)
paint
in class ImageLabel
public boolean mouseDown(java.awt.Event event, int x, int y)
mouseDown
in class java.awt.Component
public boolean mouseUp(java.awt.Event event, int x, int y)
mouseUp
in class java.awt.Component
public boolean action(java.awt.Event event, java.lang.Object arg)
action
in class java.awt.Component
Component.action(java.awt.Event, java.lang.Object)
public boolean mouseExit(java.awt.Event event, int x, int y)
mouseExit
in class java.awt.Component
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |