All Packages Class Hierarchy This Package Previous Next Index
Class tea.set.ImageButton
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----tea.set.ImageButton
- public class ImageButton
- extends Canvas
ImageButton is a widget that behaves like a regular button. But instead
of displaying a text label, it displays an image inside the button. An
ImageButton can be simply constructed by supplying a plain image. A 3D
button image will automatically generated. The default size of the
button is the size of the image. If the button is resized to a size
other than the image size, the image is scaled to the new button
size.
An optional label can be specified for the button. If a label is
specified, it will be show together with the image.
A second image can be supplied for displaying when the button is in
pressed mode. This is normally used when the button is in toggle mode.
ImageButton supports the following properties:
Property Name | Property Type | Description |
Toggle | boolean |
Toggle button mode flag. |
State | boolean |
Toggle button state. |
Label | String |
Button text label. |
Display | int |
Button display style, IMAGE_ONLY, LABEL_ONLY, or LABEL_IMAGE. |
PreferredSize | Dimension |
Button preferred size. Can be set to override the calculated size. |
LabelPos | int |
Button label position flag. |
Image | Image |
Button image. |
Image2 | Image2 |
Button pressed image. |
ImageButton generates the following events:
Event Type | Event ID | Generated |
Description |
ActionEvent | ActionEvent.ACTION_PERFORMED |
Button pressed, or state changed if toggle button. |
ActionEvent.getActionCommand() contains the button label. |
-
BOTTOM
- BOTTOM specifies the label of the button being placed at the bottom
of the button.
-
eventMgr
- EventMgr object handles added event processing and dispatching.
-
IMAGE_ONLY
- Display button image only.
-
LABEL_IMAGE
- Display button image and label.
-
LABEL_ONLY
- Display button text label only.
-
LEFT
- LEFT specifies the label of the button being placed at the left
of the button.
-
RIGHT
- RIGHT specifies the label of the button being placed at the right
of the button.
-
TOP
- TOP specifies the label of the button being placed at the top
of the button.
-
ImageButton()
- Construct an ImageButton with no image.
-
ImageButton(Image)
- Contruct an ImageButton with the supplied image.
-
ImageButton(Image, String)
- Construct an ImageButton with image and a label.
-
ImageButton(Image, String, int)
- Construct an ImageButton with image and a label.
-
addActionListener(ActionListener)
- Add an action listener.
-
getDisplay()
- Get the display style.
-
getImage()
- Get the button image.
-
getImage2()
- Get the button pressed image.
-
getLabel()
- Return the label of the button, null if none.
-
getLabelPos()
- Get the button label position.
-
getMinimumSize()
- Return the minimum size of the button.
-
getPreferredSize()
- Return the preferred size of the button.
-
getState()
- Get the current toggle state.
-
isToggle()
- Get the toggle mode.
-
paint(Graphics)
- Paint button.
-
processActionEvent(ActionEvent)
- Process and dispatch action event.
-
processEvent(AWTEvent)
- Process and dispatch event.
-
processMouseEvent(MouseEvent)
- Mouse down event causes a pressed button image to be shown.
-
removeActionListener(ActionListener)
- Remove an action listener.
-
setBackground(Color)
- Set the background color.
-
setDisplay(int)
- Set the button display style, IMAGE_ONLY, LABEL_ONLY, or
LABEL_IMAGE.
-
setEnabled(boolean)
- Enable the button.
-
setFont(Font)
- Set the font.
-
setForeground(Color)
- Set the foreground color.
-
setImage(Image)
- Set or change the image displayed by this button.
-
setImage2(Image)
- Set or change the image displayed by this button for pressed mode.
-
setLabel(String)
- Set the label for this button.
-
setLabel(String, int)
- Set the label for this button.
-
setLabelPos(int)
- Set the label position.
-
setPreferredSize(Dimension)
- Change the size of the button to dimension.
-
setState(boolean)
- Set the toggle button state.
-
setToggle(boolean)
- If toggle mode is true, the button behaves as a toggle button
(checkbox).
LABEL_ONLY
public static final int LABEL_ONLY
- Display button text label only.
IMAGE_ONLY
public static final int IMAGE_ONLY
- Display button image only.
LABEL_IMAGE
public static final int LABEL_IMAGE
- Display button image and label.
TOP
public static final int TOP
- TOP specifies the label of the button being placed at the top
of the button.
LEFT
public static final int LEFT
- LEFT specifies the label of the button being placed at the left
of the button.
BOTTOM
public static final int BOTTOM
- BOTTOM specifies the label of the button being placed at the bottom
of the button.
RIGHT
public static final int RIGHT
- RIGHT specifies the label of the button being placed at the right
of the button.
eventMgr
protected EventMgr eventMgr
- EventMgr object handles added event processing and dispatching.
ImageButton
public ImageButton()
- Construct an ImageButton with no image. ImageButton.setImage() must
be called before this component can be used.
ImageButton
public ImageButton(Image iv)
- Contruct an ImageButton with the supplied image.
- Parameters:
- iv - button image.
ImageButton
public ImageButton(Image iv,
String label)
- Construct an ImageButton with image and a label.
The default label position is below the image.
- Parameters:
- iv - button image.
- label - button label.
ImageButton
public ImageButton(Image iv,
String label,
int pos)
- Construct an ImageButton with image and a label.
A position for the label can be specified.
- Parameters:
- iv - button image.
- label - button label.
- pos - label position flag.
setToggle
public synchronized void setToggle(boolean f)
- If toggle mode is true, the button behaves as a toggle button
(checkbox). Otherwise it behaves as a regular button.
- Parameters:
- f - toggle mode.
isToggle
public boolean isToggle()
- Get the toggle mode.
- Returns:
- toggle mode.
setState
public synchronized void setState(boolean f)
- Set the toggle button state. This is only used when button is in
toggle mode.
- Parameters:
- f - toggle state.
getState
public boolean getState()
- Get the current toggle state.
- Returns:
- toggle state.
setLabel
public synchronized void setLabel(String label,
int pos)
- Set the label for this button. If there was no label, the apperance
of the button is going to change. The size of the button may also
change depending of the label and image.
- Parameters:
- label - button label.
- pos - label position flag.
setLabel
public void setLabel(String label)
- Set the label for this button. If there was no label, the apperance
of the button is going to change. The size of the button may also
change depending of the label and image.
- Parameters:
- label - button label.
getLabel
public String getLabel()
- Return the label of the button, null if none.
- Returns:
- button label.
setLabelPos
public void setLabelPos(int pos)
- Set the label position.
- Parameters:
- pos - label position flag.
getLabelPos
public int getLabelPos()
- Get the button label position.
- Returns:
- label position.
setDisplay
public synchronized void setDisplay(int style)
- Set the button display style, IMAGE_ONLY, LABEL_ONLY, or
LABEL_IMAGE.
- Parameters:
- style - display style.
getDisplay
public int getDisplay()
- Get the display style.
- Returns:
- display style.
setEnabled
public void setEnabled(boolean f)
- Enable the button.
- Overrides:
- setEnabled in class Component
setPreferredSize
public void setPreferredSize(Dimension s)
- Change the size of the button to dimension.
- Parameters:
- s - button dimension.
getMinimumSize
public Dimension getMinimumSize()
- Return the minimum size of the button.
- Returns:
- minimum size.
- Overrides:
- getMinimumSize in class Component
getPreferredSize
public Dimension getPreferredSize()
- Return the preferred size of the button.
- Returns:
- preferred size.
- Overrides:
- getPreferredSize in class Component
setImage
public synchronized void setImage(Image iv)
- Set or change the image displayed by this button.
- Parameters:
- iv - button image.
getImage
public Image getImage()
- Get the button image. This image is not filtered so it does not
have a button border.
- Returns:
- button image.
setImage2
public synchronized void setImage2(Image iv)
- Set or change the image displayed by this button for pressed mode.
- Parameters:
- iv - button image.
getImage2
public Image getImage2()
- Get the button pressed image. This image is not filtered so it does not
have a button border.
- Returns:
- button image.
setForeground
public void setForeground(Color c)
- Set the foreground color.
- Parameters:
- c - foreground color.
- Overrides:
- setForeground in class Component
setBackground
public void setBackground(Color c)
- Set the background color.
- Parameters:
- c - background color.
- Overrides:
- setBackground in class Component
setFont
public void setFont(Font f)
- Set the font.
- Parameters:
- f - font.
- Overrides:
- setFont in class Component
addActionListener
public void addActionListener(ActionListener listener)
- Add an action listener.
- Parameters:
- listener - action listener.
removeActionListener
public void removeActionListener(ActionListener listener)
- Remove an action listener.
- Parameters:
- listener - action listener.
processEvent
public void processEvent(AWTEvent e)
- Process and dispatch event.
- Parameters:
- e - event object.
- Overrides:
- processEvent in class Component
processActionEvent
public void processActionEvent(ActionEvent e)
- Process and dispatch action event.
- Parameters:
- e - action event.
paint
public void paint(Graphics g)
- Paint button.
- Parameters:
- g - Graphics context of this component.
- Overrides:
- paint in class Canvas
processMouseEvent
public void processMouseEvent(MouseEvent e)
- Mouse down event causes a pressed button image to be shown.
Mouse exit event causes a button to change back to normal state.
Mouse up event generates an action event.
- Parameters:
- e - event object.
- Overrides:
- processMouseEvent in class Component
All Packages Class Hierarchy This Package Previous Next Index