private static int columnMaxWidth(@NotNull JTable table, int col) {
    TableColumn column = table.getColumnModel().getColumn(col);
    int width = 0;
    for (int row = 0; row < table.getRowCount(); row++) {
      Component component = table.prepareRenderer(column.getCellRenderer(), row, col);

      int rendererWidth = component.getPreferredSize().width;
      width = Math.max(width, rendererWidth + table.getIntercellSpacing().width);
    }
    return width;
  }
 // make sure to get the right cell renderers
 @Override
 public TableCellRenderer getCellRenderer(int row, int column) {
   TableColumn tableColumn = getColumnModel().getColumn(column);
   TableCellRenderer renderer = tableColumn.getCellRenderer();
   if (renderer == null) {
     Class c = getColumnClass(column);
     if (c.equals(Object.class)) {
       Object o = getValueAt(row, column);
       if (o != null) c = getValueAt(row, column).getClass();
     }
     renderer = getDefaultRenderer(c);
   }
   return renderer;
 }
Beispiel #3
0
  /**
   * Creates a new MappingEditor object.
   *
   * @param mappings DOCUMENT ME!
   */
  public MappingEditor(final List<Mapping> mappings) {
    fldNames = null;
    initComponents();
    setContent(mappings);
    tblMappings.setModel(new MappingModel(mappings));
    // add alphanumeric sorting
    TableSortDecorator.decorate(tblMappings);
    scpMappings.setTransferHandler(tblMappings.getTransferHandler());
    this.tblMappings
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    final TableColumn col = tblMappings.getColumnModel().getColumn(3);
    col.getCellRenderer();
  }