Class UIGraphic
public class UIGraphic extends UIStatic
{
// Constructors
public UIGraphic();
public UIGraphic(Image image);
public UIGraphic(Image image, int style);
// Methods
public Image getImage();
public Dimension getPreferredSize();
public int getRoleCode();
public boolean imageUpdate(Image image, int flags, int x, int y,
int width, int height);
public void paint(FxGraphics g, Rectangle rect);
public void setImage(Image image);
}
This class implements a static graphic control. Typically, a UIGraphic object is used to display a graphical image on another control, such as a button. When you create a UIGraphic object, you specify the image to be displayed and an optional alignment or style. The following example shows how to use UIGraphic to create other objects.
// Construct a push button that uses UIGraphic
// to display the image stored in the variable myImage1.
// Left-align the image.
UIPushButton p =
new UIPushButton(new UIGraphic(myImage1, UIStatic.LEFT));
add(p); // Add p to the container.
// Construct a scroll viewer control that displays myImage2.
UIScrollViewer sv = new UIScrollViewer(new UIGraphic(myImage2));
add(sv);
In addition to using UIGraphic, you can use UIText and UIItem to create other static objects.
UIComponent
|
+--UIStateComponent
|
+--UICanvas
|
+--UIStatic
|
+--UIGraphic
public UIGraphic();
Creates a static graphic control with no image.
Remarks:
By default, any image added to the control will be aligned both horizontally and vertically.
public UIGraphic(Image image);
Creates a static graphic control with the specified image.
Parameter | Description |
image
| The image to be displayed within the control.
|
Remarks:
By default, the image is aligned both horizontally and vertically.
public UIGraphic(Image image, int style);
Creates a static graphic control with the specified image and style.
Parameter | Description |
image
| The image to be displayed within the control.
|
style
| The alignment and style of the control. You can pass any bitwise combination of an alignment flag and a style flag. For a list of possible flags, see the UIStatic.setFlags method.
|
Remarks:
If a vertical alignment is not specified, VCENTER is used by default. Similarly, if a horizontal alignment is not specified, HCENTER is used.
Exceptions:
IllegalArgumentException
if more than one vertical alignment, more than one horizontal alignment, or an undefined style was specified.
public Image getImage();
Retrieves the control's image.
Return Value:
Returns the Image object displayed within the control.
See Also: setImage
public Dimension getPreferredSize();
Retrieves the preferred size (in pixels) of the static graphic control.
Return Value:
Returns a Dimension object containing the preferred size.
Remarks:
The preferred size is based on the width and height of the control's image.
public int getRoleCode();
Retrieves the ROLE_SYSTEM code that best describes the role of the static graphic control.
Return Value:
Returns the ROLE_SYSTEM_GRAPHIC code.
public boolean imageUpdate(Image image, int flags, int x, int y, int width,
int height);
Incrementally draws the control's image as the bits become available.
Return Value:
Returns true if more information is needed to draw the full image; otherwise, returns false.
Parameter | Description |
image
| The control's image.
|
flags
| The flags that specify the status of the image that is being loaded. You can pass any bitwise combination of the fields that are defined in the ImageObserver interface.
|
x
| The x coordinate of the image.
|
y
| The y coordinate of the image.
|
width
| The width of the image (in pixels).
|
height
| The height of the image (in pixels).
|
public void paint(FxGraphics g, Rectangle rect);
Called by paint(Graphics g), which is inherited through UIStatic, to draw the control's image.
Return Value:
No return value.
Parameter | Description |
g
| The graphics context.
|
rect
| The rectangle to draw the control's image in.
|
Overrides:
paint(FxGraphics,Rectangle) in UIStatic.
public void setImage(Image image);
Sets the control's image.
Return Value:
No return value.
Parameter | Description |
image
| The image to be displayed within the control.
|
See Also: getImage