Package rma.swing

Class RmaJWrappingLabel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, SwingConstants

public class RmaJWrappingLabel extends JComponent implements SwingConstants
This class implements a multiple-line text label. It displays text on one or more lines, wrapping text as needed to fit in the available horizontal space.
See Also:
  • Field Details

  • Constructor Details

    • RmaJWrappingLabel

      public RmaJWrappingLabel()
      Constructs a default wrapping label. Default values are an empty text string and left alignment.
    • RmaJWrappingLabel

      public RmaJWrappingLabel(String s)
      Constructs a wrapping label that displays the specified string. The label will default to left alignment.
      Parameters:
      s - string to be displayed in label
    • RmaJWrappingLabel

      public RmaJWrappingLabel(String s, int a)
      Constructs wrapping label with the specified text and alignment.
      Parameters:
      s - the string to be displayed in label
      a - the alignment, one of LEFT, CENTERED, or RIGHT
  • Method Details

    • getTextAlignment

      public int getTextAlignment()
      Gets the current text alignment setting.
      Returns:
      the current alignment, one of LEFT, CENTERED, or RIGHT
      See Also:
    • setTextAlignment

      public void setTextAlignment(int newAlignStyle)
      Sets the text alignment.
      Parameters:
      newAlignStyle - the new alignment style, one of LEFT, CENTERED, or RIGHT
      See Also:
    • getText

      public String getText()
      Gets the current label text.
      Returns:
      the label's text string
      See Also:
    • setText

      public void setText(String newText)
      Sets the label text.
      Parameters:
      newText - the new label text
      See Also:
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • getMinimumSize

      public Dimension getMinimumSize()
      Overrides:
      getMinimumSize in class JComponent
    • paintComponent

      public void paintComponent(Graphics g)
      Paints this component using the given graphics context. This is a standard Java AWT method which typically gets called by the AWT to handle painting this component. It paints this component using the given graphics context. The graphics context clipping region is set to the bounding rectangle of this component and its [0,0] coordinate is this component's top-left corner.
      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - the graphics context used for painting
      See Also:
    • drawAlignedString

      protected void drawAlignedString(Graphics g, FontMetrics fm, int baseline, String s, int x, int y, int width)
      This helper method draws a string aligned the requested way.
      Parameters:
      g - the graphics context used for painting
      s - the string to draw
      x - the point to start drawing from, x coordinate
      y - the point to start drawing from, y coordinate
      width - the width of the area to draw in, in pixels