|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.j4me.ui.components.Component
org.j4me.ui.components.Label
public class Label
Displays a string.
If the string is wider than the screen, it is wrapped at the first non-alphanumeric character. The wrapped text is trimmed so that leading spaces do not appear. There are several special markup strings for controling spacing:
\n
- Goes to a newline and adds a 1/2 space separator
\r
- Goes to a newline, but does not add a separator
setFont
and setFontColor
methods.
Override this class to display strings in a new way. For example
a font backed by images of the characters can be used by re-implementing
paint
, getWidth
, and getHeight
. A good way to
generate font images is with the
AngelCode Bitmap Font Generator.
Field Summary |
---|
Fields inherited from class org.j4me.ui.components.Component |
---|
container, HIGHLIGHTED_BORDER_WIDTH |
Constructor Summary | |
---|---|
Label()
Constructs an empty label. |
|
Label(java.lang.String text)
Constructs a label. |
Method Summary | |
---|---|
static java.lang.String[] |
breakIntoLines(javax.microedition.lcdui.Font font,
java.lang.String string,
int width)
Breaks string apart at line breaks. |
javax.microedition.lcdui.Font |
getFont()
|
int |
getFontColor()
|
int |
getHeight()
|
java.lang.String |
getLabel()
|
protected int[] |
getPreferredComponentSize(Theme theme,
int viewportWidth,
int viewportHeight)
Returns the dimensions of the label for the current string. |
protected void |
invalidate()
Signals that the Component's size needs to be updated. |
protected void |
paintComponent(javax.microedition.lcdui.Graphics g,
Theme theme,
int width,
int height,
boolean selected)
Paints this label component. |
void |
setFont(javax.microedition.lcdui.Font font)
|
void |
setFontColor(int color)
|
void |
setLabel(java.lang.String text)
|
Methods inherited from class org.j4me.ui.components.Component |
---|
acceptsInput, getHorizontalAlignment, getPreferredSize, getScreen, getWidth, getX, getY, hideNotify, isShown, keyPressed, keyReleased, keyRepeated, paint, paintRect, pointerDragged, pointerPressed, pointerReleased, repaint, setHorizontalAlignment, showNotify, visible |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Label()
setLabel
.
public Label(java.lang.String text)
text
- is what the label displays.Method Detail |
---|
protected void invalidate()
Component
invalidate
in class Component
Component.invalidate()
public java.lang.String getLabel()
public void setLabel(java.lang.String text)
text
- is the string to display. If null
the label will
be hidden.public javax.microedition.lcdui.Font getFont()
Font
used to display the label. If null
the
theme's font will be used.Theme.getFont()
public void setFont(javax.microedition.lcdui.Font font)
font
- is the font to use for this label. If null
the
theme's font will be used.Theme.getFont()
public int getFontColor()
Theme.getFontColor()
public void setFontColor(int color)
color
- is the font color used to display the label. If negative the
theme's font will be used.Theme.getFontColor()
protected void paintComponent(javax.microedition.lcdui.Graphics g, Theme theme, int width, int height, boolean selected)
paintComponent
in class Component
g
- is the Graphics
object to be used for rendering the item.theme
- is the application's theme. Use it to get fonts and colors.width
- is the width, in pixels, to paint the component.height
- is the height, in pixels, to paint the component.selected
- is true
when this components is currently selected
and false
when it is not.Component.paintComponent(Graphics, Theme, int, int, boolean)
protected int[] getPreferredComponentSize(Theme theme, int viewportWidth, int viewportHeight)
getPreferredComponentSize
in class Component
theme
- is the application's Theme
.viewportWidth
- is the width of the viewable area, in pixels,
the component can use.viewportHeight
- is the height of the viewable area, in pixels,
the component can use.
Component.getPreferredComponentSize(Theme, int, int)
public int getHeight()
getHeight
in class Component
public static java.lang.String[] breakIntoLines(javax.microedition.lcdui.Font font, java.lang.String string, int width)
string
apart at line breaks. The returned array has
strings that can be written using font
in fewer than width
pixels.
The string
will be split apart at non-alphanumeric characters.
However, if a string is too long and cannot be broken nicely, it will
be split at the last alphanumeric character that fits the line
width
.
Newline characters ('\n'
) are automatically made into line
breaks. An additional empty line, represented by a null
string in the returned array, is added. It can then be painted as
a space to indicate a new paragraph.
font
- is the Font
used to write string
.string
- is the text to split. If null
then null
will be returned.width
- is the maximum number of pixels wide each string part
can be.
string
broken apart at line
breaks.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |