Class TextIcon
- java.lang.Object
-
- org.bidib.wizard.mvc.common.view.icon.TextIcon
-
- All Implemented Interfaces:
PropertyChangeListener,EventListener,Icon
public class TextIcon extends Object implements Icon, PropertyChangeListener
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:- Horizontally - does normal rendering of the text by using the Graphics.drawString(...) method
- Vertically - Each character is displayed on a separate line
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTextIcon.Layout
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FontgetFont()Get the Font used to render the text.ColorgetForeground()Get the foreground Color used to render the text.intgetIconHeight()Gets the height of this icon.intgetIconWidth()Gets the width of this icon.TextIcon.LayoutgetLayout()Get the Layout enumintgetPadding()Get the padding used when rendering the textStringgetText()Get the text String that will be rendered on the IconvoidpaintIcon(Component c, Graphics g, int x, int y)Paint the icons of this compound icon at the specified locationvoidpropertyChange(PropertyChangeEvent e)voidsetFont(Font font)Set the Font to be used for rendering the textvoidsetForeground(Color foreground)Set the foreground Color to be used for rendering the textvoidsetPadding(int padding)By default the size of the Icon is based on the size of the rendered text.voidsetText(String text)Set the text to be rendered on the Icon
-
-
-
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 addedtext- 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 addedtext- the text to be rendered on the Iconlayout- specify the layout of the text. Must be one of the Layout enums: HORIZONTAL or VERTICAL
-
-
Method Detail
-
getLayout
public TextIcon.Layout getLayout()
Get the Layout enum- Returns:
- the Layout enum
-
getText
public String getText()
Get the text String that will be rendered on the Icon- Returns:
- the text of the Icon
-
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
-
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
-
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
-
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
-
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
-
getPadding
public int getPadding()
Get the padding used when rendering the text- Returns:
- the padding specified in pixels
-
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
-
getIconWidth
public int getIconWidth()
Gets the width of this icon.- Specified by:
getIconWidthin interfaceIcon- Returns:
- the width of the icon in pixels.
-
getIconHeight
public int getIconHeight()
Gets the height of this icon.- Specified by:
getIconHeightin interfaceIcon- Returns:
- the height of the icon in pixels.
-
paintIcon
public void paintIcon(Component c, Graphics g, int x, int y)
Paint the icons of this compound icon at the specified location
-
propertyChange
public void propertyChange(PropertyChangeEvent e)
- Specified by:
propertyChangein interfacePropertyChangeListener
-
-