Class PrintableTable

All Implemented Interfaces:
WindowListener, ImageObserver, MenuContainer, Closeable, Serializable, AutoCloseable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable, FontChangeListener, PrintableView, SaveableTable<TableModel>

public class PrintableTable extends JTable implements PrintableView, SaveableTable<TableModel>, FontChangeListener, Closeable, WindowListener
The class extends JTable to make the table printable with page headers and page counts. It also implicitly recognizes if the TableModel implements ComparableProvidingTableModel so as to optimize use of RowSorters, and adds support for clipboard copying cell values to the system clipboard. It also listens to font changes so the table row heights can be adjusted, and implements Closeable so it can be deregistered from the FontCache when the table is no longer used.
Author:
Andrew Pavlin, KA2DDO
See Also:
  • Constructor Details

    • PrintableTable

      public PrintableTable(TableModel dm, String pageHeaderFormat)
      Constructs a JTable that is initialized with dm as the data model, a default column model, and a default selection model.
      Parameters:
      dm - the data model for the table
      pageHeaderFormat - String of message format for injecting print date/time and page number in a page header
  • Method Details

    • paramString

      protected String paramString()
      Returns a string representation of this table. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.
      Overrides:
      paramString in class JTable
      Returns:
      a string representation of this table
    • printThisView

      public void printThisView()
      Print this PrintableView to the Java printing subsystem. All operations necessary, including finding an appropriate print service, creating some type of print job, and sending the contents to the job, are the responsibility of this method and the methods it calls.
      Specified by:
      printThisView in interface PrintableView
    • exportAsCsv

      public void exportAsCsv(NonshareableBufferedPrintStream ps)
      Export the table as a CSV file.
      Specified by:
      exportAsCsv in interface SaveableTable<TableModel>
      Parameters:
      ps - PrintStream to write the CSV file to
    • getTableModel

      public TableModel getTableModel()
      Get the data model of the table.
      Specified by:
      getTableModel in interface SaveableTable<TableModel>
      Returns:
      TableModel used by the table
    • setFontCategory

      public void setFontCategory(String fontCategory)
      Specify the font category for font changes of interest.
      Parameters:
      fontCategory - String name of font category
    • fontChanged

      public void fontChanged(String category, Font newFont)
      Report that the font choice for the specified category has changed.
      Specified by:
      fontChanged in interface FontChangeListener
      Parameters:
      category - String font family name (as defined by Font class)
      newFont - actual font instance
    • setFont

      public void setFont(Font font)
      Overrides:
      setFont in class JComponent
    • close

      public void close() throws IOException
      Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs
    • finalize

      protected void finalize() throws Throwable
      Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. This subclass attempts to unload any TableModels this table might be using that are listening to non-GUI data sources to prevent memory leaks.
      Overrides:
      finalize in class Object
      Throws:
      Throwable - the Exception raised by this method
    • windowActivated

      public void windowActivated(WindowEvent e)
      Invoked when the Window is set to be the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.
      Specified by:
      windowActivated in interface WindowListener
    • windowOpened

      public void windowOpened(WindowEvent e)
      Invoked the first time a window is made visible.
      Specified by:
      windowOpened in interface WindowListener
    • windowClosing

      public void windowClosing(WindowEvent e)
      Invoked when the user attempts to close the window from the window's system menu.
      Specified by:
      windowClosing in interface WindowListener
    • windowClosed

      public void windowClosed(WindowEvent e)
      Invoked when a window has been closed as the result of calling dispose on the window.
      Specified by:
      windowClosed in interface WindowListener
    • windowIconified

      public void windowIconified(WindowEvent e)
      Invoked when a window is changed from a normal to a minimized state. For many platforms, a minimized window is displayed as the icon specified in the window's iconImage property.
      Specified by:
      windowIconified in interface WindowListener
      See Also:
    • windowDeiconified

      public void windowDeiconified(WindowEvent e)
      Invoked when a window is changed from a minimized to a normal state.
      Specified by:
      windowDeiconified in interface WindowListener
    • windowDeactivated

      public void windowDeactivated(WindowEvent e)
      Invoked when a Window is no longer the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.
      Specified by:
      windowDeactivated in interface WindowListener