|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.tbee.swing.MultiLineLabel
public class MultiLineLabel
This class is taken from O'Reilly's Java in a Nutshell volume 1
It allows for a label which displays more than one line of text.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
protected int |
alignment
The default alignment of the text is LEFT |
static int |
CENTER
Used to set the alingment of the text to the center. |
static int |
LEFT
Used to set the alingment of the text to the left. |
protected int |
line_ascent
How far below the "line" a line of text extends, base on the font. |
protected int |
line_height
The height of a line of text, based on the font used to display it. |
protected int[] |
line_widths
The widths of each line of text, based on the font. |
protected String[] |
lines
The text to display on the label. |
protected int |
margin_height
The amount of space to place around the text, top to bottom. |
protected int |
margin_width
The amount of space to place around the longest line of text, left to right. |
protected int |
max_width
The maximum width of all the lines of text, based on font. |
protected int |
num_lines
The number of individual lines of text to display on the label. |
static int |
RIGHT
Used to set the alingment of the text to the right. |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
MultiLineLabel(String label)
The simplest of the constructors, all that is passed to it is the text that is to be displayed. |
|
MultiLineLabel(String label,
int alignment)
This constructor is given the message to display and the alingment. |
|
MultiLineLabel(String label,
int margin_width,
int margin_height)
This constructor allows the message, margin width, and margin height to be passed in. |
|
MultiLineLabel(String label,
int margin_width,
int margin_height,
int alignment)
This constructor allows the message, margin width, margin height, and alingment to be passed set. |
|
| Method Summary | |
|---|---|
void |
addNotify()
addNotify is used by the MultiLineLabel to know when the label is set up enough to allow for the font to be measured. |
String |
getText()
|
static void |
main(String[] args)
|
protected void |
measure()
This protected method is used by the MultiLineLabel to measure the amount of space which will be required to display the text, given whatever font we are displaying it in. |
Dimension |
minimumSize()
minimumSize is used by the layout manager to determine the minimum amount of space need to display the text. |
protected void |
newLabel(String label)
This protected method is called by the MultiLineLabel to set up the text for display. |
void |
paint(Graphics g)
paint is the method which is called by the layout manager to draw the MultiLineLabel, with text to the screen. |
Dimension |
preferredSize()
preferredSize is used by the layout manager to determine how much space the MultiLineLabel needs to display itself properly. |
void |
setAlignment(int a)
This method allows for the alignment to be set, after the alingment is set the label is redisplayed by calling the repaint method. |
void |
setFont(Font font)
Set the font to be used to display the text. |
void |
setForeground(Color color)
This method allows the text color to be changed. |
void |
setLabel(String label)
Set the label to display. |
void |
setMarginHeight(int mh)
The margin height, specifies the amount of space from the top and bottom most line to the edge of the label. |
void |
setMarginWidth(int mw)
The margin width, specifies the amount of space from the two ends of the longest line of text, to the edge of the label. |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int LEFT
public static final int CENTER
public static final int RIGHT
protected String[] lines
protected int num_lines
protected int margin_width
protected int margin_height
protected int line_height
protected int line_ascent
protected int[] line_widths
protected int max_width
protected int alignment
| Constructor Detail |
|---|
public MultiLineLabel(String label)
label - The text to display, as a String.
public MultiLineLabel(String label,
int alignment)
label - The text to display, as a String.alignment - The alignment to display the text.
public MultiLineLabel(String label,
int margin_width,
int margin_height)
label - The text to display, as a String.margin_width - The margin width to use while displaying the text.margin_height - The margin height to use while displaying the text.
public MultiLineLabel(String label,
int margin_width,
int margin_height,
int alignment)
label - The text to display, as a String.margin_width - The margin width to use while displaying the text.margin_height - The margin height to use while displaying the text.alignment - The alingment to use while displaying the text.| Method Detail |
|---|
public void addNotify()
addNotify in class JComponentpublic Dimension minimumSize()
minimumSize in class Containerpublic void paint(Graphics g)
paint in class JComponentg - The Graphics to draw upon.protected void measure()
protected void newLabel(String label)
label - The text to be displayed.public Dimension preferredSize()
preferredSize in class Containerpublic void setAlignment(int a)
a - The alingment to use when displaying the text. Passed using
the static ints defined in this class.public void setFont(Font font)
setFont in class JComponentfont - The Font to use.public void setForeground(Color color)
setForeground in class JComponentcolor - The Color to display the text in.public void setLabel(String label)
label - The text to display, passed in as a String.public String getText()
public void setMarginHeight(int mh)
mh - The margin height, in the form of an integer.public void setMarginWidth(int mw)
mw - The margin width, in the form of an integer.
public static void main(String[] args)
throws Exception
Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||