All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.wizards.awt.JMultilineLabel
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----com.sun.wizards.awt.JMultilineLabel
- public class JMultilineLabel
- extends Canvas
This class is used in the same way as MultilineLabel.
Here is the code for this applet:
import java.applet.Applet;
import java.awt.*;
import com.sun.wizards.awt.*;
public class Test extends Applet
{
public void init()
{
add(new JMultilineLabel("Line 1\n(Notice the lines are centered) Line 2\nLine3",
JMultilineLabel.CENTER));
}
}
This example is from the book _Java in a Nutshell_ by David Flanagan.
Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates.
You may study, use, modify, and distribute this example for any purpose.
This example is provided WITHOUT WARRANTY either expressed or implied.
- See Also:
- MultilineLabel
-
alignment
- The alignment of the text
-
CENTER
- Alignment constant
-
LEFT
- Alignment constant
-
line_ascent
- Font height above baseline
-
line_height
- Total height of the font
-
line_widths
- How wide each line is.
-
lines
- The lines of text to display
-
margin_height
- The top and bottom margins
-
margin_width
- The left and right margins.
-
max_width
- The width of the widest line
-
num_lines
- The number of lines
-
RIGHT
- Alignment constant
-
JMultilineLabel(String)
- Break the label up into separate lines, and save the other info.
-
JMultilineLabel(String, int)
- Break the label up into separate lines, and save the other info.
-
JMultilineLabel(String, int, int)
- Break the label up into separate lines, and save the other info.
-
JMultilineLabel(String, int, int, int)
-
Break the label up into separate lines, and save the other info.
-
addNotify()
- This method is invoked after our Canvas is first created
but before it can actually be displayed.
-
getAlignment()
- Gets the alignment of this component.
-
getMarginHeight()
- Gets the top-bottom margins of this component.
-
getMarginWidth()
- Gets the left-right margins of this component.
-
getMinimumSize()
- This method is called when the layout manager wants to know
the bare minimum amount of space we need to get by.
-
getPreferredSize()
-
This method is called by a layout manager when it wants to
know how big we'd like to be.
-
measure()
-
This method figures out how the font is, and how wide each
line of the label is, and how wide the widest line is.
-
newLabel(String)
-
This method breaks a specified label up into an array of lines.
-
paint(Graphics)
-
This method draws the label (applets use the same method).
-
setAlignment(int)
- Sets the alignment to the specified alignment.
-
setFont(Font)
- Sets Font to the specified font.
-
setForeground(Color)
- Sets the foreground to the specified color.
-
setLabel(String)
- Sets label to the specified label.
-
setMarginHeight(int)
- Sets the margin height to the specified height.
-
setMarginWidth(int)
- Sets the margin width to the specified width.
LEFT
public static final int LEFT
- Alignment constant
CENTER
public static final int CENTER
- Alignment constant
RIGHT
public static final int RIGHT
- Alignment constant
lines
protected String lines[]
- The lines of text to display
num_lines
protected int num_lines
- The number of lines
margin_width
protected int margin_width
- The left and right margins.
margin_height
protected int margin_height
- The top and bottom margins
line_height
protected int line_height
- Total height of the font
line_ascent
protected int line_ascent
- Font height above baseline
line_widths
protected int line_widths[]
- How wide each line is.
max_width
protected int max_width
- The width of the widest line
alignment
protected int alignment
- The alignment of the text
JMultilineLabel
public JMultilineLabel(String label,
int margin_width,
int margin_height,
int alignment)
- Break the label up into separate lines, and save the other info.
- Parameters:
- label - The label to add.
- margin_width - The width of the left and right margins.
- margin_height - The height of the top and bottom margins.
- alignment - Which side to align the text on.
JMultilineLabel
public JMultilineLabel(String label,
int margin_width,
int margin_height)
- Break the label up into separate lines, and save the other info.
Defaults to LEFT alignment.
- Parameters:
- label - The label to add.
- margin_width - The width of the left and right margins.
- margin_height - The height of the top and bottom margins.
JMultilineLabel
public JMultilineLabel(String label,
int alignment)
- Break the label up into separate lines, and save the other info.
Defaults to 10 for both left-right and top-bottom margins.
- Parameters:
- label - The label to add.
- alignment - Which side to align the text on.
JMultilineLabel
public JMultilineLabel(String label)
- Break the label up into separate lines, and save the other info.
Defaults to 10 for both left-right and top-bottom margins. Also defaults to LEFT
alignment.
- Parameters:
- label - The label to add.
newLabel
protected void newLabel(String label)
- This method breaks a specified label up into an array of lines.
It uses the StringTokenizer utility class.
- Parameters:
- label - The label to break up into lines.
measure
protected void measure()
- This method figures out how the font is, and how wide each
line of the label is, and how wide the widest line is.
setLabel
public void setLabel(String label)
- Sets label to the specified label.
- Parameters:
- label - The label to add to this component.
setFont
public void setFont(Font f)
- Sets Font to the specified font.
- Parameters:
- f - The Font to set this component to.
- Overrides:
- setFont in class Component
setForeground
public void setForeground(Color c)
- Sets the foreground to the specified color.
- Parameters:
- c - The desired color to set this component to.
- Overrides:
- setForeground in class Component
setAlignment
public void setAlignment(int a)
- Sets the alignment to the specified alignment.
- Parameters:
- a - The desired calignment to set this component to.
setMarginWidth
public void setMarginWidth(int mw)
- Sets the margin width to the specified width.
- Parameters:
- mw - The desired left-right margins.
setMarginHeight
public void setMarginHeight(int mh)
- Sets the margin height to the specified height.
- Parameters:
- mh - The desired top-bottom margins to set this component to.
getAlignment
public int getAlignment()
- Gets the alignment of this component.
- Returns:
- The alignment of this component.
getMarginWidth
public int getMarginWidth()
- Gets the left-right margins of this component.
- Returns:
- The left-right margins of this component.
getMarginHeight
public int getMarginHeight()
- Gets the top-bottom margins of this component.
- Returns:
- The top-bottom margins of this component.
addNotify
public void addNotify()
- This method is invoked after our Canvas is first created
but before it can actually be displayed. After we've
invoked our superclass's addNotify() method, we have font
metrics and can successfully call measure() to figure out
how big the label is.
- Overrides:
- addNotify in class Canvas
getPreferredSize
public Dimension getPreferredSize()
- This method is called by a layout manager when it wants to
know how big we'd like to be.
- Returns:
- The Preferred dimensions for this component.
- Overrides:
- getPreferredSize in class Component
getMinimumSize
public Dimension getMinimumSize()
- This method is called when the layout manager wants to know
the bare minimum amount of space we need to get by.
- Returns:
- The minimum size for this component.
- Overrides:
- getMinimumSize in class Component
paint
public void paint(Graphics g)
- This method draws the label (applets use the same method).
Note that it handles the margins and the alignment, but that
it doesn't have to worry about the color or font--the superclass
takes care of setting those in the Graphics object we're passed.
- Parameters:
- g - The Graphics context for this component.
- Overrides:
- paint in class Canvas
All Packages Class Hierarchy This Package Previous Next Index