Class TextTitle

java.lang.Object
org.jfree.chart.title.Title
org.jfree.chart.title.TextTitle
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
DateTitle

public class TextTitle
extends Title
implements Serializable, Cloneable
A chart title that displays a text string.
Author:
David Berry
See Also:
Serialized Form
  • Field Details

    • DEFAULT_FONT

      public static final Font DEFAULT_FONT
      The default font.
    • DEFAULT_TEXT_PAINT

      public static final Paint DEFAULT_TEXT_PAINT
      The default text color.
  • Constructor Details

    • TextTitle

      public TextTitle()
      Creates a new title, using default attributes where necessary.
    • TextTitle

      public TextTitle​(String text)
      Creates a new title, using default attributes where necessary.
      Parameters:
      text - the title text.
    • TextTitle

      public TextTitle​(String text, Font font)
      Creates a new title, using default attributes where necessary.
      Parameters:
      text - the title text.
      font - the title font.
    • TextTitle

      public TextTitle​(String text, Font font, Paint paint)
      Creates a new title, using default attributes where necessary.
      Parameters:
      text - the title text.
      font - the title font.
      paint - the title color.
    • TextTitle

      public TextTitle​(String text, Font font, org.jfree.ui.HorizontalAlignment horizontalAlignment)
      Creates a new title, using default attributes where necessary.

      For the horizontal alignment, use the constants (LEFT, RIGHT and CENTER) defined in the Title class.

      Parameters:
      text - the title text.
      font - the title font.
      horizontalAlignment - the horizontal alignment.
    • TextTitle

      public TextTitle​(String text, Font font, Paint paint, org.jfree.ui.RectangleEdge position, org.jfree.ui.HorizontalAlignment horizontalAlignment, org.jfree.ui.VerticalAlignment verticalAlignment, org.jfree.ui.Spacer spacer)
      Creates a new title.

      For the titlePosition, horizontalAlignment and verticalAlignment, use the constants defined in the Title class.

      Parameters:
      text - the text for the title (null not permitted).
      font - the font (null not permitted).
      paint - the color (null not permitted).
      position - the title position (null not permitted).
      horizontalAlignment - the horizontal alignment (null not permitted).
      verticalAlignment - the vertical alignment (null not permitted).
      spacer - the space to leave around the outside of the title.
  • Method Details

    • getText

      public String getText()
      Returns the title text.
      Returns:
      the text (never null).
    • setText

      public void setText​(String text)
      Sets the title to the specified text and sends a TitleChangeEvent to all registered listeners.
      Parameters:
      text - the text (null not permitted).
    • getFont

      public Font getFont()
      Returns the font used to display the title string.
      Returns:
      the font (never null).
    • setFont

      public void setFont​(Font font)
      Sets the font used to display the title string. Registered listeners are notified that the title has been modified.
      Parameters:
      font - the new font (null not permitted).
    • getPaint

      public Paint getPaint()
      Returns the paint used to display the title string.
      Returns:
      the paint (never null).
    • setPaint

      public void setPaint​(Paint paint)
      Sets the paint used to display the title string. Registered listeners are notified that the title has been modified.
      Parameters:
      paint - the new paint (null not permitted).
    • getBackgroundPaint

      public Paint getBackgroundPaint()
      Returns the background paint.
      Returns:
      the paint (possibly null).
    • setBackgroundPaint

      public void setBackgroundPaint​(Paint paint)
      Sets the background paint and sends a TitleChangeEvent to all registered listeners. If you set this attribute to null, no background is painted (which makes the title background transparent).
      Parameters:
      paint - the background paint (null permitted).
    • getPreferredWidth

      public float getPreferredWidth​(Graphics2D g2, float height)
      Returns the preferred width of the title. This will only be called when the title is being drawn at the left or right of a chart.
      Specified by:
      getPreferredWidth in class Title
      Parameters:
      g2 - the graphics device.
      height - the height.
      Returns:
      the preferred width of the title.
    • getPreferredHeight

      public float getPreferredHeight​(Graphics2D g2, float width)
      Returns the preferred height of the title.
      Specified by:
      getPreferredHeight in class Title
      Parameters:
      g2 - the graphics device.
      width - the width.
      Returns:
      the preferred height of the title.
    • draw

      public void draw​(Graphics2D g2, Rectangle2D area)
      Draws the title on a Java 2D graphics device (such as the screen or a printer).
      Specified by:
      draw in class Title
      Parameters:
      g2 - the graphics device.
      area - the area allocated for the title.
    • equals

      public boolean equals​(Object obj)
      Tests this title for equality with another object.
      Overrides:
      equals in class Title
      Parameters:
      obj - the object.
      Returns:
      true or false.
    • hashCode

      public int hashCode()
      Returns a hash code.
      Overrides:
      hashCode in class Title
      Returns:
      a hash code.
    • clone

      public Object clone() throws CloneNotSupportedException
      Returns a clone of this object.
      Overrides:
      clone in class Title
      Returns:
      a clone of this object.
      Throws:
      CloneNotSupportedException - never.