|
|
||||||||||||||||||||||||||||||||
Class UITextpublic 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 ConstructorsUITextpublic UIText(); UITextpublic UIText(String text); UITextpublic UIText(String text, int style); MethodsgetPreferredSizepublic Dimension getPreferredSize(); getRoleCodepublic int getRoleCode(); paintpublic void paint(FxGraphics g, Rectangle rect); setFocusedpublic void setFocused(boolean on); setHotpublic void setHot(boolean on); setNamepublic void setName(String text); setSelectedpublic void setSelected(boolean on);
|
© 1998 Microsoft Corporation. All rights reserved. Terms of use. |