public class GLabel extends GObject
GLabel
class is a graphical object whose appearance
consists of a text string.Modifier and Type | Field and Description |
---|---|
static Font |
DEFAULT_FONT
The default font used to display strings.
|
Constructor and Description |
---|
GLabel(String str)
Creates a new
GLabel object initialized to contain the specified string. |
GLabel(String str,
double x,
double y)
Creates a new
GLabel object with its baseline origin at the
specified position. |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(double x,
double y)
Returns true if this label contains the given x/y point.
|
double |
getAscent()
Returns the distance this string extends above the baseline.
|
GRectangle |
getBounds()
Returns a
GRectangle that specifies the bounding box for the string. |
double |
getDescent()
Returns the distance this string descends below the baseline.
|
Font |
getFont()
Returns the font in which the
GLabel is displayed. |
FontMetrics |
getFontMetrics()
Returns a
FontMetrics object describing the dimensions of this string. |
double |
getHeight()
Returns the height of this string, as it appears on the display.
|
String |
getLabel()
Returns the string displayed by this object.
|
String |
getText()
Returns the string displayed by this object.
|
double |
getWidth()
Returns the width of this string, as it appears on the display.
|
void |
paint2d(Graphics2D g)
Implements the
paint2d operation for this graphical object. |
String |
paramString()
Returns a string indicating the parameters of this object.
|
void |
setBottomY(double bottomY)
Sets the bottom y-coordinate of this object to the given y value.
|
void |
setCenterLocation(double centerX,
double centerY)
Sets the central x/y-coordinates of this object to the given x/y values.
|
void |
setCenterY(double centerY)
Sets the central y-coordinate of this object to the given y value.
|
void |
setFont(Font font)
Changes the font used to display the
GLabel . |
void |
setFont(String str)
Changes the font used to display the
GLabel as specified by
the string str , which is interpreted in the style of
Font.decode . |
void |
setLabel(String str)
Changes the string stored within the
GLabel object, so that
a new text string appears on the display. |
void |
setText(String str)
Changes the string stored within the
GLabel object, so that
a new text string appears on the display. |
void |
setTopY(double topY)
Sets the top y-coordinate of this object to the given y value.
|
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, clone, colorName, colorName, colorNameFriendly, contains, createTransformedGraphics, fireActionEvent, fireActionEvent, fireMouseListeners, getBottomY, getCenterLocation, getCenterX, getCenterY, getColor, getComponent, getLineWidth, getLocation, getMatrix, getObjectColor, getParent, getRightX, getSize, getX, getY, intersects, isAntiAliasing, isVisible, move, movePolar, paint, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, rotate, scale, scale, sendBackward, sendForward, sendToBack, sendToFront, setAntiAliasing, setCenterLocation, setCenterX, setColor, setLineWidth, setLocation, setLocation, setParent, setRightX, setVisible, setX, setY, start, start, toString, updateEnabledList
public GLabel(String str)
GLabel
object initialized to contain the specified string.str
- The initial contents of the GLabel
public GLabel(String str, double x, double y)
GLabel
object with its baseline origin at the
specified position.str
- The initial contents of the GLabel
x
- The x-coordinate of the label originy
- The y-coordinate of the baseline for the labelpublic boolean contains(double x, double y)
public double getAscent()
public GRectangle getBounds()
GRectangle
that specifies the bounding box for the string.public double getDescent()
public Font getFont()
GLabel
is displayed.public FontMetrics getFontMetrics()
FontMetrics
object describing the dimensions of this string.FontMetrics
object describing the dimensions of this stringpublic double getHeight()
public String getLabel()
public String getText()
public double getWidth()
public void paint2d(Graphics2D g)
paint2d
operation for this graphical object. This method
is not called directly by clients.public String paramString()
paramString
in class GObject
public void setBottomY(double bottomY)
setBottomY
in class GObject
bottomY
- The new bottom y-coordinate for the objectpublic void setCenterLocation(double centerX, double centerY)
setCenterLocation
in class GObject
centerX
- The new central x-coordinate for the objectcenterY
- The new central y-coordinate for the objectpublic void setCenterY(double centerY)
setCenterY
in class GObject
centerY
- The new central y-coordinate for the objectpublic void setFont(Font font)
GLabel
. This call will
usually change the size of the displayed object and will therefore affect
the result of calls to getSize
and getBounds
.font
- A Font
object indicating the new fontpublic void setFont(String str)
GLabel
as specified by
the string str
, which is interpreted in the style of
Font.decode
. The usual format of the font string is
family-style-size
where both style and size are optional. If any of these
parts are specified as an asterisk, the existing value is retained.
str
- A String
specifying the new fontpublic void setLabel(String str)
GLabel
object, so that
a new text string appears on the display.
Equivalent to setText.str
- The new string to displaypublic void setText(String str)
GLabel
object, so that
a new text string appears on the display.
Equivalent to setLabel.str
- The new string to displaypublic void setTopY(double topY)
bottomY
- The new top y-coordinate for the object