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.

Graphic of JMultilineLabel displaying centered text.

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

Variable Index

 o alignment
The alignment of the text
 o CENTER
Alignment constant
 o LEFT
Alignment constant
 o line_ascent
Font height above baseline
 o line_height
Total height of the font
 o line_widths
How wide each line is.
 o lines
The lines of text to display
 o margin_height
The top and bottom margins
 o margin_width
The left and right margins.
 o max_width
The width of the widest line
 o num_lines
The number of lines
 o RIGHT
Alignment constant

Constructor Index

 o JMultilineLabel(String)
Break the label up into separate lines, and save the other info.
 o JMultilineLabel(String, int)
Break the label up into separate lines, and save the other info.
 o JMultilineLabel(String, int, int)
Break the label up into separate lines, and save the other info.
 o JMultilineLabel(String, int, int, int)
Break the label up into separate lines, and save the other info.

Method Index

 o addNotify()
This method is invoked after our Canvas is first created but before it can actually be displayed.
 o getAlignment()
Gets the alignment of this component.
 o getMarginHeight()
Gets the top-bottom margins of this component.
 o getMarginWidth()
Gets the left-right margins of this component.
 o getMinimumSize()
This method is called when the layout manager wants to know the bare minimum amount of space we need to get by.
 o getPreferredSize()
This method is called by a layout manager when it wants to know how big we'd like to be.
 o 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.
 o newLabel(String)
This method breaks a specified label up into an array of lines.
 o paint(Graphics)
This method draws the label (applets use the same method).
 o setAlignment(int)
Sets the alignment to the specified alignment.
 o setFont(Font)
Sets Font to the specified font.
 o setForeground(Color)
Sets the foreground to the specified color.
 o setLabel(String)
Sets label to the specified label.
 o setMarginHeight(int)
Sets the margin height to the specified height.
 o setMarginWidth(int)
Sets the margin width to the specified width.

Variables

 o LEFT
 public static final int LEFT
Alignment constant

 o CENTER
 public static final int CENTER
Alignment constant

 o RIGHT
 public static final int RIGHT
Alignment constant

 o lines
 protected String lines[]
The lines of text to display

 o num_lines
 protected int num_lines
The number of lines

 o margin_width
 protected int margin_width
The left and right margins.

 o margin_height
 protected int margin_height
The top and bottom margins

 o line_height
 protected int line_height
Total height of the font

 o line_ascent
 protected int line_ascent
Font height above baseline

 o line_widths
 protected int line_widths[]
How wide each line is.

 o max_width
 protected int max_width
The width of the widest line

 o alignment
 protected int alignment
The alignment of the text

Constructors

 o 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.
 o 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.
 o 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.
 o 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.

Methods

 o 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.
 o 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.

 o setLabel
 public void setLabel(String label)
Sets label to the specified label.

Parameters:
label - The label to add to this component.
 o 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
 o 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
 o setAlignment
 public void setAlignment(int a)
Sets the alignment to the specified alignment.

Parameters:
a - The desired calignment to set this component to.
 o setMarginWidth
 public void setMarginWidth(int mw)
Sets the margin width to the specified width.

Parameters:
mw - The desired left-right margins.
 o 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.
 o getAlignment
 public int getAlignment()
Gets the alignment of this component.

Returns:
The alignment of this component.
 o getMarginWidth
 public int getMarginWidth()
Gets the left-right margins of this component.

Returns:
The left-right margins of this component.
 o getMarginHeight
 public int getMarginHeight()
Gets the top-bottom margins of this component.

Returns:
The top-bottom margins of this component.
 o 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
 o 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
 o 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
 o 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