Class JTableHelper

java.lang.Object
nz.ac.waikato.cms.gui.core.JTableHelper

public class JTableHelper extends Object
A helper class for JTable, e.g. calculating the optimal colwidth.
Version:
$Revision: 14842 $
Author:
FracPete (fracpete at waikato dot ac dot nz)
  • Field Details

    • LOGGER

      protected static Logger LOGGER
      for logging.
    • MAX_ROWS

      public static final int MAX_ROWS
      the maximum number of rows to use for calculation.
      See Also:
    • m_Table

      protected JTable m_Table
      the table to work with.
  • Constructor Details

    • JTableHelper

      public JTableHelper(JTable table)
      initializes the object.
      Parameters:
      table - the table to work on
  • Method Details

    • getJTable

      public JTable getJTable()
      returns the JTable.
      Returns:
      the table to work on
    • calcColumnWidth

      public int calcColumnWidth(int col)
      calcs the optimal column width of the given column.
      Parameters:
      col - the column index
      Returns:
      the optimal width
    • calcColumnWidthBounded

      public int calcColumnWidthBounded(int col, int max)
      calcs the optimal column width of the given column.
      Parameters:
      col - the column index
      max - the limit for the column width, -1 for unlimited
      Returns:
      the optimal width
    • calcColumnWidth

      public static int calcColumnWidth(JTable table, int col)
      Calculates the optimal width for the column of the given table. The calculation is based on the preferred width of the header and cell renderer.
      Taken from the newsgroup de.comp.lang.java with some modifications.
      Taken from FOPPS/EnhancedTable - http://fopps.sourceforge.net/
      Parameters:
      table - the table to calculate the column width
      col - the column to calculate the widths
      Returns:
      the width, -1 if error
    • calcColumnWidthBounded

      public static int calcColumnWidthBounded(JTable table, int col, int max)
      Calculates the optimal width for the column of the given table. The calculation is based on the preferred width of the header and cell renderer.
      Taken from the newsgroup de.comp.lang.java with some modifications.
      Taken from FOPPS/EnhancedTable - http://fopps.sourceforge.net/
      Parameters:
      table - the table to calculate the column width
      col - the column to calculate the widths
      max - the limit for the column width, -1 for unlimited
      Returns:
      the width, -1 if error
    • calcHeaderWidth

      public int calcHeaderWidth(int col)
      calcs the optimal header width of the given column.
      Parameters:
      col - the column index
      Returns:
      the optimal width
    • calcHeaderWidthBounded

      public int calcHeaderWidthBounded(int col, int max)
      calcs the optimal header width of the given column.
      Parameters:
      col - the column index
      max - the limit for the column width, -1 for unlimited
      Returns:
      the optimal width
    • calcHeaderWidth

      public static int calcHeaderWidth(JTable table, int col)
      Calculates the optimal width for the header of the given table. The calculation is based on the preferred width of the header renderer.
      Parameters:
      table - the table to calculate the column width
      col - the column to calculate the widths
      Returns:
      the width, -1 if error
    • calcHeaderWidthBounded

      public static int calcHeaderWidthBounded(JTable table, int col, int max)
      Calculates the optimal width for the header of the given table. The calculation is based on the preferred width of the header renderer.
      Parameters:
      table - the table to calculate the column width
      col - the column to calculate the widths
      max - the limit for the column width, -1 for unlimited
      Returns:
      the width, -1 if error
    • setOptimalColumnWidth

      public void setOptimalColumnWidth(int col)
      sets the optimal column width for the given column.
      Parameters:
      col - the column index
    • setOptimalColumnWidthBounded

      public void setOptimalColumnWidthBounded(int col, int max)
      sets the optimal column width for the given column.
      Parameters:
      col - the column index
      max - the maximum column width, -1 for unlimited
    • setOptimalColumnWidth

      public static void setOptimalColumnWidth(JTable table, int col)
      sets the optimal column width for the given column.
      Parameters:
      table - the table to work on
      col - the column index
    • setOptimalColumnWidthBounded

      public static void setOptimalColumnWidthBounded(JTable table, int col, int max)
      sets the optimal column width for the given column.
      Parameters:
      table - the table to work on
      col - the column index
      max - the maximum column width, -1 for unlimited
    • setOptimalColumnWidth

      public void setOptimalColumnWidth()
      sets the optimal column width for all columns.
    • setOptimalColumnWidthBounded

      public void setOptimalColumnWidthBounded(int max)
      sets the optimal column width for all columns.
    • setOptimalColumnWidth

      public static void setOptimalColumnWidth(JTable table)
      sets the optimal column width for alls column if the given table.
      Parameters:
      table - the table to work on
    • setOptimalColumnWidthBounded

      public static void setOptimalColumnWidthBounded(JTable table, int max)
      sets the optimal column width for alls column if the given table.
      Parameters:
      table - the table to work on
    • setOptimalHeaderWidth

      public void setOptimalHeaderWidth(int col)
      sets the optimal header width for the given column.
      Parameters:
      col - the column index
    • setOptimalHeaderWidthBounded

      public void setOptimalHeaderWidthBounded(int col, int max)
      sets the optimal header width for the given column.
      Parameters:
      col - the column index
      max - the column width limit, -1 for unlimited
    • setOptimalHeaderWidth

      public static void setOptimalHeaderWidth(JTable table, int col)
      sets the optimal header width for the given column.
      Parameters:
      table - the table to work on
      col - the column index
    • setOptimalHeaderWidthBounded

      public static void setOptimalHeaderWidthBounded(JTable table, int col, int max)
      sets the optimal header width for the given column.
      Parameters:
      table - the table to work on
      col - the column index
      max - the column width limit, -1 for unlimited
    • setOptimalHeaderWidth

      public void setOptimalHeaderWidth()
      sets the optimal header width for all columns.
    • setOptimalHeaderWidth

      public static void setOptimalHeaderWidth(JTable table)
      sets the optimal header width for alls column if the given table.
      Parameters:
      table - the table to work with
    • scrollToVisible

      public void scrollToVisible(int row, int col)
      Assumes table is contained in a JScrollPane. Scrolls the cell (rowIndex, vColIndex) so that it is visible within the viewport.
      Parameters:
      row - the row index
      col - the column index
    • scrollToVisible

      public static void scrollToVisible(JTable table, int row, int col)
      Assumes table is contained in a JScrollPane. Scrolls the cell (rowIndex, vColIndex) so that it is visible within the viewport.
      Parameters:
      table - the table to work with
      row - the row index
      col - the column index