Java Code Examples for javax.swing.table.TableModel#getColumnClass()

The following examples show how to use javax.swing.table.TableModel#getColumnClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefineryUtilities.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a panel that contains a table based on the specified table model.
 *
 * @param model  the table model to use when constructing the table.
 *
 * @return The panel.
 */
public static JPanel createTablePanel(final TableModel model) {

    final JPanel panel = new JPanel(new BorderLayout());
    final JTable table = new JTable(model);
    for (int columnIndex = 0; columnIndex < model.getColumnCount(); columnIndex++) {
        final TableColumn column = table.getColumnModel().getColumn(columnIndex);
        final Class c = model.getColumnClass(columnIndex);
        if (c.equals(Number.class)) {
            column.setCellRenderer(new NumberCellRenderer());
        }
    }
    panel.add(new JScrollPane(table));
    return panel;

}
 
Example 2
Source File: RefineryUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a panel that contains a table based on the specified table model.
 *
 * @param model  the table model to use when constructing the table.
 *
 * @return The panel.
 */
public static JPanel createTablePanel(TableModel model) {

    JPanel panel = new JPanel(new BorderLayout());
    JTable table = new JTable(model);
    for (int columnIndex = 0; columnIndex < model.getColumnCount();
            columnIndex++) {
        TableColumn column = table.getColumnModel().getColumn(columnIndex);
        Class c = model.getColumnClass(columnIndex);
        if (c.equals(Number.class)) {
            column.setCellRenderer(new NumberCellRenderer());
        }
    }
    panel.add(new JScrollPane(table));
    return panel;

}
 
Example 3
Source File: RefineryUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a panel that contains a table based on the specified table model.
 *
 * @param model  the table model to use when constructing the table.
 *
 * @return The panel.
 */
public static JPanel createTablePanel(TableModel model) {

    JPanel panel = new JPanel(new BorderLayout());
    JTable table = new JTable(model);
    for (int columnIndex = 0; columnIndex < model.getColumnCount(); 
            columnIndex++) {
        TableColumn column = table.getColumnModel().getColumn(columnIndex);
        Class c = model.getColumnClass(columnIndex);
        if (c.equals(Number.class)) {
            column.setCellRenderer(new NumberCellRenderer());
        }
    }
    panel.add(new JScrollPane(table));
    return panel;

}
 
Example 4
Source File: AbstractDemoHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected JComponent createDefaultTable(final TableModel data)
{
  final JTable table = new JTable(data);
  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

  for (int columnIndex = 0; columnIndex < data.getColumnCount(); columnIndex++)
  {
    final TableColumn column = table.getColumnModel().getColumn(columnIndex);
    column.setMinWidth(50);
    final Class c = data.getColumnClass(columnIndex);
    if (c.equals(Number.class))
    {
      column.setCellRenderer(new NumberCellRenderer());
    }
  }

  return new JScrollPane
      (table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
          JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
}
 
Example 5
Source File: AbstractDemoFrame.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected JComponent createDefaultTable(final TableModel data)
{
  final JTable table = new JTable(data);
  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

  for (int columnIndex = 0; columnIndex < data
      .getColumnCount(); columnIndex++)
  {
    final TableColumn column = table.getColumnModel().getColumn(columnIndex);
    column.setMinWidth(50);
    final Class c = data.getColumnClass(columnIndex);
    if (c.equals(Number.class))
    {
      column.setCellRenderer(new NumberCellRenderer());
    }
  }

  return new JScrollPane
      (table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
          JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
}
 
Example 6
Source File: TableModelInfo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void printTableModel( final TableModel mod, final PrintStream out ) {
  out.println( "Tablemodel contains " + mod.getRowCount() + " rows." ); //$NON-NLS-1$ //$NON-NLS-2$
  for ( int i = 0; i < mod.getColumnCount(); i++ ) {
    out.println( "Column: " + i + " Name=" + mod.getColumnName( i ) + "; DataType=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        + mod.getColumnClass( i ) );
  }

  out.println( "Checking the data inside" ); //$NON-NLS-1$
  for ( int rows = 0; rows < mod.getRowCount(); rows++ ) {
    for ( int i = 0; i < mod.getColumnCount(); i++ ) {
      final Object value = mod.getValueAt( rows, i );
      final Class<?> c = mod.getColumnClass( i );
      if ( value == null ) {
        out.println( "ValueAt (" + rows + ", " + i + ") is null" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      } else {
        if ( c.isAssignableFrom( value.getClass() ) == false ) {
          out.println( "ValueAt (" + rows + ", " + i + ") is not assignable from " + c ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        } else if ( c.equals( Object.class ) ) {
          out.println( "ValueAt (" + rows + ", " + i + ") is in a generic column and is of "
          //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
              + "type " + value.getClass() ); //$NON-NLS-1$
        } else {
          out.println( "ValueAt (" + rows + ", " + i + ") is in a typed column and is of "
          //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
              + "type " + value.getClass() ); //$NON-NLS-1$
        }
      }
    }
  }
}
 
Example 7
Source File: CachableTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void initDefaultMetaData( final TableModel model ) {
  for ( int i = 0; i < model.getColumnCount(); i++ ) {
    final String columnName = model.getColumnName( i );
    final Class columnType = model.getColumnClass( i );
    final DefaultDataAttributes attributes = new DefaultDataAttributes();
    attributes.setMetaAttribute( MetaAttributeNames.Core.NAMESPACE, MetaAttributeNames.Core.NAME,
                                 DefaultConceptQueryMapper.INSTANCE, columnName );
    attributes.setMetaAttribute( MetaAttributeNames.Core.NAMESPACE, MetaAttributeNames.Core.TYPE,
                                 DefaultConceptQueryMapper.INSTANCE, columnType );
    columnAttributes.add( attributes );
  }
  tableAttributes = EmptyDataAttributes.INSTANCE;
}
 
Example 8
Source File: CachableTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean isSafeToCache( final TableModel model ) {
  final int columnCount = model.getColumnCount();
  for ( int i = 0; i < columnCount; i += 1 ) {
    Class columnClass = model.getColumnClass( i );
    while ( columnClass.isArray() ) {
      columnClass = columnClass.getComponentType();
    }
    if ( String.class.equals( columnClass ) ) {
      continue;
    }
    if ( Number.class.isAssignableFrom( columnClass ) ) {
      continue;
    }
    if ( Date.class.isAssignableFrom( columnClass ) ) {
      continue;
    }
    if ( Boolean.class.equals( columnClass ) ) {
      continue;
    }
    if ( columnClass.isPrimitive() ) {
      continue;
    }
    if ( Paint.class.isAssignableFrom( columnClass ) ) {
      continue;
    }
    if ( Shape.class.isAssignableFrom( columnClass ) ) {
      continue;
    }
    if ( Stroke.class.isAssignableFrom( columnClass ) ) {
      continue;
    }
    if ( columnClass.isEnum() ) {
      continue;
    }
    return false;
  }
  return true;
}
 
Example 9
Source File: OfflineTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public OfflineTableModel( final TableModel model, final DataAttributeContext dataAttributeContext ) {
  columnCount = model.getColumnCount();
  columnTypes = new Class[columnCount];
  columnNames = new String[columnCount];
  columnAttributes = new DefaultDataAttributes[columnCount];
  values = new Object[columnCount];
  tableAttributes = new DefaultDataAttributes();

  for ( int i = 0; i < columnCount; i++ ) {
    columnTypes[i] = model.getColumnClass( i );
    columnNames[i] = model.getColumnName( i );
    columnAttributes[i] = new DefaultDataAttributes();
  }
  if ( model instanceof MetaTableModel ) {
    final MetaTableModel metaTableModel = (MetaTableModel) model;
    tableAttributes.merge( metaTableModel.getTableAttributes(), dataAttributeContext );

    for ( int i = 0; i < columnCount; i++ ) {
      columnAttributes[i].merge( metaTableModel.getColumnAttributes( i ), dataAttributeContext );
    }
  }
  if ( model.getRowCount() > 0 ) {
    for ( int i = 0; i < columnCount; i++ ) {
      values[i] = model.getValueAt( 0, i );
    }
  }
}