Groovy Documentation

com.wordpress.tipsforjava.swing
[Java] Class TextIcon

java.lang.Object
  com.wordpress.tipsforjava.swing.TextIcon
All Implemented Interfaces:
Icon, PropertyChangeListener

public class TextIcon
extends Object

The TextIcon will paint a String of text as an Icon. The Icon can be used by any Swing component that supports icons. TextIcon supports two different layout styles:

TextIcon was designed to be rendered on a specific JComponent as it requires FontMetrics information in order to calculate its size and to do the rendering. Therefore, it should only be added to component it was created for. By default the text will be rendered using the Font and foreground color of its associated component. However, this class does allow you to override these properties.
Authors:
Rob Camick
Darryl Burke


Nested Class Summary
enum TextIcon.Layout

 
Field Summary
private JComponent component

The TextIcon will paint a String of text as an Icon.

private Font font

private Color foreground

private int iconHeight

private int iconWidth

private TextIcon.Layout layout

private int padding

private int[] stringWidths

private String[] strings

private String text

 
Constructor Summary
TextIcon(JComponent component, String text)

Convenience constructor to create a TextIcon with a HORIZONTAL layout.

TextIcon(JComponent component, String text, TextIcon.Layout layout)

Create a TextIcon specifying all the properties.

 
Method Summary
private void calculateIconDimensions()

Calculate the size of the Icon using the FontMetrics of the Font.

Font getFont()

Get the Font used to render the text.

Color getForeground()

Get the foreground Color used to render the text.

int getIconHeight()

Gets the height of this icon.

int getIconWidth()

Gets the width of this icon.

TextIcon.Layout getLayout()

Get the Layout enum

int getPadding()

Get the padding used when rendering the text

String getText()

Get the text String that will be rendered on the Icon

void paintIcon(Component c, Graphics g, int x, int y)

Paint the icons of this compound icon at the specified location

void propertyChange(PropertyChangeEvent e)

void setFont(Font font)

Set the Font to be used for rendering the text

void setForeground(Color foreground)

Set the foreground Color to be used for rendering the text

void setPadding(int padding)

By default the size of the Icon is based on the size of the rendered text.

void setText(String text)

Set the text to be rendered on the Icon

TextIcon valueOf(String name)

Returns the enum constant of this type with the specified name.

TextIcon[] values()

Returns an array containing the constants of this enum type, in the order they are declared.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

component

private JComponent component
The TextIcon will paint a String of text as an Icon. The Icon can be used by any Swing component that supports icons. TextIcon supports two different layout styles: TextIcon was designed to be rendered on a specific JComponent as it requires FontMetrics information in order to calculate its size and to do the rendering. Therefore, it should only be added to component it was created for. By default the text will be rendered using the Font and foreground color of its associated component. However, this class does allow you to override these properties.
Authors:
Rob Camick
Darryl Burke


font

private Font font


foreground

private Color foreground


iconHeight

private int iconHeight


iconWidth

private int iconWidth


layout

private TextIcon.Layout layout


padding

private int padding


stringWidths

private int[] stringWidths


strings

private String[] strings


text

private String text


 
Constructor Detail

TextIcon

public TextIcon(JComponent component, String text)
Convenience constructor to create a TextIcon with a HORIZONTAL layout.
Parameters:
component - the component to which the icon will be added
text - the text to be rendered on the Icon


TextIcon

public TextIcon(JComponent component, String text, TextIcon.Layout layout)
Create a TextIcon specifying all the properties.
Parameters:
component - the component to which the icon will be added
text - the text to be rendered on the Icon
layout - specify the layout of the text. Must be one of the Layout enums: HORIZONTAL or VERTICAL


 
Method Detail

calculateIconDimensions

private void calculateIconDimensions()
Calculate the size of the Icon using the FontMetrics of the Font.


getFont

public Font getFont()
Get the Font used to render the text. This will default to the Font of the component unless the Font has been overridden by using the setFont() method.
Returns:
the Font used to render the text


getForeground

public Color getForeground()
Get the foreground Color used to render the text. This will default to the foreground Color of the component unless the foreground Color has been overridden by using the setForeground() method.
Returns:
the Color used to render the text


getIconHeight

de
	public
public int getIconHeight()
Gets the height of this icon.
Returns:
the height of the icon in pixels.


getIconWidth

de
	public
public int getIconWidth()
Gets the width of this icon.
Returns:
the width of the icon in pixels.


getLayout

public TextIcon.Layout getLayout()
Get the Layout enum
Returns:
the Layout enum


getPadding

public int getPadding()
Get the padding used when rendering the text
Returns:
the padding specified in pixels


getText

public String getText()
Get the text String that will be rendered on the Icon
Returns:
the text of the Icon


paintIcon

de
	public
public void paintIcon(Component c, Graphics g, int x, int y)
Paint the icons of this compound icon at the specified location
Parameters:
c - The component to which the icon is added
g - the graphics context
x - the X coordinate of the icon's top-left corner
y - the Y coordinate of the icon's top-left corner


propertyChange

public void propertyChange(PropertyChangeEvent e)


setFont

public void setFont(Font font)
Set the Font to be used for rendering the text
Parameters:
font - the Font to be used for rendering the text


setForeground

public void setForeground(Color foreground)
Set the foreground Color to be used for rendering the text
Parameters:
foreground - the foreground Color to be used for rendering the text


setPadding

public void setPadding(int padding)
By default the size of the Icon is based on the size of the rendered text. You can specify some padding to be added to the start and end of the text when it is rendered.
Parameters:
padding - the padding amount in pixels


setText

public void setText(String text)
Set the text to be rendered on the Icon
Parameters:
text - the text to be rendered on the Icon


valueOf

TextIcon valueOf(String name)
Returns the enum constant of this type with the specified name.


values

TextIcon[] values()
Returns an array containing the constants of this enum type, in the order they are declared.


 

Groovy Documentation