Class SwingMessageTable<D>

Type Parameters:
D - the type of document identifiers
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable

public class SwingMessageTable<D> extends JTable
Multi-line rendering for messages, to be included in a Swing based GUI.

Inspired by https://coderanch.com/t/341698/java/TableRenderer-multiple-lines-text

For "setLineWrap(true)": thanks to https://www.experts-exchange.com/questions/21475798/jtable-line-wrap.html

See Also:
  • Field Details

    • COLNUM_LOCATION

      protected static final int COLNUM_LOCATION
      Number of the message location column
      See Also:
    • COLNUM_TEXT

      protected static final int COLNUM_TEXT
      Number of the message text column
      See Also:
    • standardColor_warn

      public static final Color standardColor_warn
      Background color for warning messages
    • standardColor_error

      public static final Color standardColor_error
      Background color for error messages
    • standardColor_neutral

      public static final Color standardColor_neutral
      Background color for all other messages
    • standardColor_hint

      public static final Color standardColor_hint
      Background color for hint messages
    • colorWarn

      protected Color colorWarn
      Background color for warning messages
    • colorError

      protected Color colorError
      Background color for error messages
    • colorNeutral

      protected Color colorNeutral
      Background color for all other messages
    • colorHint

      protected Color colorHint
      Background color for hint messages
    • separatorColor

      protected Color separatorColor
      Background color for separator line.
    • separatorKey

      @Opt protected @Opt String separatorKey
      Message text which makes a bold horizontal line, nothing else.
    • translate

      protected Function<? super SimpleMessage<D>,String> translate
      Function used to translate the message text and its arguments. (Kind, location, cause, etc. do not need multi-lingual support.)
    • indentString

      protected String indentString
      The string prepended n times before the text to indicate the nesting of logg messages.
  • Constructor Details

    • SwingMessageTable

      public SwingMessageTable(MessageStore_<SimpleMessage<D>>.TableModel model)
      Only constructor, needs an instance of a table model. After construction, setup() must be called for the completion of this instance configuration.
      Parameters:
      model - the table model to display
  • Method Details

    • setColorWarn

      public Color setColorWarn(Color nc)
      Set the color used to signal warning messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setColorError

      public Color setColorError(Color nc)
      Set the color used to signal error messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setColorHint

      public Color setColorHint(Color nc)
      Set the color used to signal hint messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setSeparatorKey

      @Opt public @Opt String setSeparatorKey(@Opt @Opt String separatorKey)
      Sets the message text which causes the message to be shown simply as one big grey separating block.
      Parameters:
      separatorKey - which will be shown as a separating block
      Returns:
      the overwritten value.
    • setTranslate

      public void setTranslate(Function<? super SimpleMessage<D>,String> fun)
      Set the function used to translate the message text and its arguments.
      Parameters:
      fun - the new function for translation
    • setIndentString

      public void setIndentString(String s)
      Set the string to visualize the indentation of messages.
      Parameters:
      s - the string to visualize the indentation of messages.
    • getMessageAt

      protected SimpleMessage<D> getMessageAt(int row)
      Get the message from the underlying message store at the given position.
      Parameters:
      row - the index position of the message
      Returns:
      the message at the given position in the message store
    • prepareRenderer

      public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
      Filters for separatorKey and draws a thick line instead. (Thanks to Robert Camick Table Row Rendering.)
      Overrides:
      prepareRenderer in class JTable
      Parameters:
      row - the row in the current view. Is the same as in the TableModel as long as columns are not re-arranged.
      column - the column in the current view. Is the same as in the TableModel as long as rows are not re-sorted.
    • setup

      public SwingMessageTable<D> setup()
      Completion of the configuration after construction. This method sets Swing attributes by method invocations. These are separate from the constructor to avoid "this-escapes" with future subclasses.

      ("Drag-and-Drop"/"DnD" is disabled since no handler is explicitly set.) (Column header is shown with no contents, to allow interactive change of column width.)

    • setwidth_minpref

      protected void setwidth_minpref(int colnum, int width)
      Sets minimal und preferred width of one particular column.
      Parameters:
      colnum - the number of the column
      width - the value for minimal and preferred width