Class UIStatic
public abstract class UIStatic extends UICanvas
{
// Fields
public static final int BOTTOM;
public static final int BOTTOMLEFT;
public static final int BOTTOMRIGHT;
public static final int CENTERED;
public static final int HCENTER;
public static final int HOTTRACK;
public static final int LEFT;
public static final int NOEDGE;
public static final int NOKEY;
public static final int RIGHT;
public static final int TOP;
public static final int TOPLEFT;
public static final int TOPRIGHT;
public static final int VCENTER;
// Constructors
public UIStatic();
public UIStatic(int style);
// Methods
public Dimension calcString(String text);
public Dimension calcString(FxGraphics g, String text);
public void drawString(FxGraphics g, String text, Rectangle rect);
public Rectangle getContentBounds();
public boolean isKeyable();
public void paint(FxGraphics g);
public void paint(FxGraphics g, Rectangle rect);
public void setFlags(int style);
public void setHot(boolean on);
}
This class implements an abstract static control. A UIStatic object simply displays static information (such as a text string or a graphical image), and is typically used for the content of another object. The following diagram shows the classes that extend UIStatic.
UIStatic
|
+--UIText
|
+--UIGraphic
|
+--UIItem
UIStatic defines the HOTTRACK style, which allows the control's hot-tracked state to be set. For a list of other style and alignment flags, see the setFlags method.
Note The hot-track color is the same color as the button text color. As a result, hot-tracking does not appear to be functional.
UIComponent
|
+--UIStateComponent
|
+--UICanvas
|
+--UIStatic
public UIStatic();
Creates a static control with a style of CENTERED.
public UIStatic(int style);
Creates a static control with the specified style.
Parameter | Description |
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 setFlags.
|
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 Dimension calcString(String text);
Calculates the dimensions of the specified text (in pixels), based on the font of the current graphics context.
Return Value:
Returns a Dimension object containing the width and height of the text.
Parameter | Description |
text
| The text string.
|
Remarks:
This method is used by UIText and UIItem when the dimensions of the associated text strings are needed.
public Dimension calcString(FxGraphics g, String text);
Calculates the dimensions of the specified text (in pixels), based on the font of the specified graphics context.
Return Value:
Returns a Dimension object containing the width and height of the text.
Parameter | Description |
g
| The graphics context. If null, the graphics context of the control is used.
|
text
| The text string.
|
Remarks:
This method is used by UIText and UIItem when the dimensions of the associated text strings are needed.
public void drawString(FxGraphics g, String text, Rectangle rect);
Draws the specified text within the given rectangle, using the specified graphics context.
Return Value:
No return value.
Parameter | Description |
g
| The graphics context.
|
text
| The text to be drawn.
|
rect
| The rectangle to draw the text in.
|
Remarks:
This method draws the text according to the control's current states. drawString is called by UIText.paint and UIItem.paint.
public Rectangle getContentBounds();
Retrieves the bounding rectangle of the control's contents.
Return Value:
Returns a Rectangle object that defines the content area within the control's coordinate space.
Remarks:
This method is called by paint(FxGraphics g) to draw the control's contents in the bounding rectangle.
public boolean isKeyable();
Determines whether the static control can receive keyboard input.
Return Value:
Returns true if the control can receive keyboard input; otherwise, returns false.
Remarks:
If the NOKEY style is set, this method returns false.
public void paint(FxGraphics g);
Draws the static control.
Return Value:
No return value.
Parameter | Description |
g
| The graphics context.
|
Remarks:
This method determines the bounding rectangle of the control's contents, and then calls paint(FxGraphics g, Rectangle rect) to draw the contents in this region.
public void paint(FxGraphics g, Rectangle rect);
Draws the static control's contents within the specified rectangle.
Return Value:
No return value.
Parameter | Description |
g
| The graphics context.
|
rect
| The rectangle in which to draw the control's contents.
|
Remarks:
This method is called by paint(FxGraphics g), which passes the rectangle returned from getContentBounds. By default, the UIStatic implementation of this method does nothing; however, it is fully implemented in UIText and UIItem.
public void setFlags(int style);
Sets the alignment and style of the static control.
Return Value:
No return value.
Parameter | Description |
style
| The alignment and style of the control. You can pass any bitwise combination of an alignment flag and a style flag. Possible flags include those shown in the following table.
|
Remarks:
This method redraws the control to reflect the new style. 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 void setHot(boolean on);
Sets or clears the hot-tracked state of the static control.
Return Value:
No return value.
Parameter | Description |
on
| If true, the hot-tracked state is set; otherwise, it is cleared.
|
Remarks:
The control must have the HOTTRACK style for the hot-tracked state to be set or cleared.
- BOTTOM
- Specifies that the content is vertically bottom-aligned to the bottom of the control.
- BOTTOMLEFT
- Specifies that the content is horizontally left-aligned and vertically bottom-aligned.
- BOTTOMRIGHT
- Specifies that the content is horizontally right-aligned and vertically bottom-aligned.
- CENTERED
- Specifies that the content is both horizontally and vertically centered within the control.
- HCENTER
- Specifies that the content is horizontally centered horizontally within the control.
- HOTTRACK
- Specifies that the control is hot-tracked. When this style flag is set, the control's hot-tracked state can be toggled through calls to the setHot method. When the hot-tracked state is set, any text displayed by the control is drawn in the hot-tracked color. By default, the hot-tracked state is set when the mouse enters the control; the state is cleared when the mouse exits. This behavior allows the control that is currently under the mouse to be identified.
- LEFT
- Specifies that the content is horizontally left-aligned within the control.
- NOEDGE
- Specifies that the control has no edge of padding around the content; normally, there is a 2 pixel border around all sides when computing the preferred size.
- NOKEY
- Specifies that the control is not keyable. This style is used when the control is not part of a control component and will never need to have the keyboard focus. A label is an example of this style.
- RIGHT
- Specifies that the content is horizontally right-aligned within the control.
- TOP
- Specifies that the content is vertically top-aligned to the top of the control.
- TOPLEFT
- Specifies that the content is horizontally left-aligned and vertically top-aligned.
- TOPRIGHT
- Specifies that the content is horizontally right-aligned and vertically top-aligned.
- VCENTER
- Specifies that the content is vertically centered within the control.