Packages
 In this topic

*Constructors

*Methods

 

Packages   PreviousThis PackageNext
Package com.ms.ui   Previous This
Package
Next

 


Class UIText

public class UIText extends UIStatic
{
  // Constructors
  public UIText();
  public UIText(String text);
  public UIText(String text, int style);

  // Methods
  public Dimension getPreferredSize();
  public int getRoleCode();
  public void paint(FxGraphics g, Rectangle rect);
  public void setFocused(boolean on);
  public void setHot(boolean on);
  public void setName(String text);
  public void setSelected(boolean on);
}

This class implements a static text control. Typically, UIText object is used to display text on another control, such as a button. When you create a UIText object, you specify the text to be displayed and an optional alignment or style. The following example shows how to use UIText to create other objects.

// Construct a check box button that uses
// UIText to display the "Check Box" text string.
// Left-align the text.
UICheckButton c = 
   new UICheckButton(new UIText("Check Box", UIStatic.LEFT));
add(c);  // Add c to the container.

UIText overrides the paint method to reflect the control's current states. For example, if the control is hot-tracked, the text changes colors when the mouse enters the control. The color is restored when the mouse exits. If the control is currently selected, the text is white on a dark background. Whenever the state of the control changes, paint is called to redraw the control.

Note For a control to be hot-tracked, you must specify the HOTTRACK style when you create it. When the mouse enters the control, the hot-tracked state is then set through a call to setHot, and the text turns blue. When the mouse exits, the hot-tracked state is cleared. Be aware that calling setHot will have no effect if the HOTTRACK style was never set.

The following example demonstrates the use of the HOTTRACK style flag. Many classes have a default mechanism for creating hot-tracked controls. For example, when constructing a button with a String, the HOTTRACK style is set internally, and the control is automatically hot-tracked.

// Construct a push button using UIText.
// Specify that the control is hot-tracked
// by using the HOTTRACK flag.
UIPushButton p1 = 
   new UIPushButton(new UIText("Hot-tracked with UIText", 
                               UIStatic.HOTTRACK));

// Construct a push button using a String.
// The control is automatically hot-tracked.
UIPushButton p2 = new UIPushButton("Hot-tracked by default");

// Construct a push button that is not hot-tracked.
// In this case, the button must be created with UIText.
UIPushButton p3 = new UIPushButton(new UIText("Not hot-tracked"));

add(p1);
add(p2);
add(p3);

In addition to using UIText, you can use UIGraphic and UIItem to create other static objects.

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
        |
        +--UIText

Constructors

UIText

public UIText();

Creates a static text control with no text.

Remarks:

By default, any text added to the control will be aligned both horizontally and vertically.

UIText

public UIText(String text);

Creates a static text control with the specified text.

ParameterDescription
text The text to be displayed within the control.

Remarks:

By default, the text is aligned both horizontally and vertically.

UIText

public UIText(String text, int style);

Creates a static text control with the specified text and style.

ParameterDescription
text The text 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.

Methods

getPreferredSize

public Dimension getPreferredSize();

Retrieves the preferred size (in pixels) of the static text control.

Return Value:

Returns a Dimension object containing the preferred size.

Remarks:

The preferred size is based on the dimensions of the control's text in the current font.

getRoleCode

public int getRoleCode();

Retrieves the ROLE_SYSTEM code that best describes the role of the static text control.

Return Value:

Returns the ROLE_SYSTEM_STATICTEXT code.

paint

public void paint(FxGraphics g, Rectangle rect);

Called by paint(Graphics g), inherited through UIStatic, to draw the control's text.

Return Value:

No return value.

ParameterDescription
g The graphics context.
rect The rectangle in which to draw the control's text.

Remarks:

This method draws the control's text and background to reflect the control's current states. For more information about states, see the UIText overview.

Overrides:

paint(FxGraphics,Rectangle) in UIStatic.

setFocused

public void setFocused(boolean on);

Sets or clears the focus state of the static text control.

Return Value:

No return value.

ParameterDescription
on If true, the focus state is set; otherwise, it is cleared.

Remarks:

This method redraws the control to display the new state. For more information about states, see the UIText overview.

setHot

public void setHot(boolean on);

Sets or clears the hot-tracked state of the static text control.

Return Value:

No return value.

ParameterDescription
on If true, the hot-tracked state is set; otherwise, it is cleared.

Remarks:

This method redraws the control to display the new state.

Note The control must have the HOTTRACK style for the hot-tracked state to be set or cleared. For more information about hot-tracking, see the UIText overview.

Overrides:

setHot(boolean) in UIStatic.

setName

public void setName(String text);

Sets the control's text.

Return Value:

No return value.

ParameterDescription
text The text to be displayed within the control.

Remarks:

The getName method (inherited through UICanvas) enables you to retrieve the control's current text.

setSelected

public void setSelected(boolean on);

Sets or clears the selected state of the static text control.

Return Value:

No return value.

ParameterDescription
on If true, the selected state is set; otherwise, it is cleared.

Remarks:

This method redraws the control to display the new state. For more information about states, see the UIText overview.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.