Class TextLineNumber

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, CaretListener, DocumentListener

public class TextLineNumber
extends JPanel
implements CaretListener, DocumentListener, PropertyChangeListener
This class will display line numbers for a related text component. The text component must use the same line height for each line. TextLineNumber supports wrapped lines and will highlight the line number of the current line in the text component. This class was designed to be used as a component added to the row header of a JScrollPane.
See Also:
Serialized Form
  • Field Details

  • Constructor Details

    • TextLineNumber

      public TextLineNumber​(JTextComponent component)
      Create a line number component for a text component. This minimum display width will be based on 3 digits.
      Parameters:
      component - the related text component
    • TextLineNumber

      public TextLineNumber​(JTextComponent component, int minimumDisplayDigits)
      Create a line number component for a text component.
      Parameters:
      component - the related text component
      minimumDisplayDigits - the number of digits used to calculate the minimum width of the component
  • Method Details

    • getUpdateFont

      public boolean getUpdateFont()
      Gets the update font property
      Returns:
      the update font property
    • setUpdateFont

      public void setUpdateFont​(boolean updateFont)
      Set the update font property. Indicates whether this Font should be updated automatically when the Font of the related text component is changed.
      Parameters:
      updateFont - when true update the Font and repaint the line numbers, otherwise just repaint the line numbers.
    • getBorderGap

      public int getBorderGap()
      Gets the border gap
      Returns:
      the border gap in pixels
    • setBorderGap

      public void setBorderGap​(int borderGap)
      The border gap is used in calculating the left and right insets of the border. Default value is 5.
      Parameters:
      borderGap - the gap in pixels
    • getCurrentLineForeground

      public Color getCurrentLineForeground()
      Gets the current line rendering Color
      Returns:
      the Color used to render the current line number
    • setCurrentLineForeground

      public void setCurrentLineForeground​(Color currentLineForeground)
      The Color used to render the current line digits. Default is Coolor.RED.
      Parameters:
      currentLineForeground - the Color used to render the current line
    • getDigitAlignment

      public float getDigitAlignment()
      Gets the digit alignment
      Returns:
      the alignment of the painted digits
    • setDigitAlignment

      public void setDigitAlignment​(float digitAlignment)
      Specify the horizontal alignment of the digits within the component. Common values would be:
      • TextLineNumber.LEFT
      • TextLineNumber.CENTER
      • TextLineNumber.RIGHT (default)
      Parameters:
      digitAlignment - the horizontal alignment of the digits within the component
    • getMinimumDisplayDigits

      public int getMinimumDisplayDigits()
      Gets the minimum display digits
      Returns:
      the minimum display digits
    • setMinimumDisplayDigits

      public void setMinimumDisplayDigits​(int minimumDisplayDigits)
      Specify the mimimum number of digits used to calculate the preferred width of the component. Default is 3.
      Parameters:
      minimumDisplayDigits - the number digits used in the preferred width calculation
    • paintComponent

      public void paintComponent​(Graphics g)
      Draw the line numbers
      Overrides:
      paintComponent in class JComponent
    • getTextLineNumber

      protected String getTextLineNumber​(int rowStartOffset)
    • caretUpdate

      public void caretUpdate​(CaretEvent e)
      Specified by:
      caretUpdate in interface CaretListener
    • changedUpdate

      public void changedUpdate​(DocumentEvent e)
      Specified by:
      changedUpdate in interface DocumentListener
    • insertUpdate

      public void insertUpdate​(DocumentEvent e)
      Specified by:
      insertUpdate in interface DocumentListener
    • removeUpdate

      public void removeUpdate​(DocumentEvent e)
      Specified by:
      removeUpdate in interface DocumentListener
    • propertyChange

      public void propertyChange​(PropertyChangeEvent evt)
      Specified by:
      propertyChange in interface PropertyChangeListener