Search in sources :

Example 46 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class TableContentView method fitCellSizeToRenderer.

/**
 * Sets the preferred column width and returns the maximum of the
 * preferred row heights according to each column's renderer.
 * This method should only be called when the table is built up from
 * scratch.
 * @return the best initial row height (this must be set elsewhere)
 */
int fitCellSizeToRenderer() {
    TableColumnModel colModel = getColumnModel();
    int bestRowHeight = 16;
    for (Enumeration<TableColumn> enu = colModel.getColumns(); enu.hasMoreElements(); ) {
        TableColumn col = enu.nextElement();
        TableCellRenderer renderer = col.getCellRenderer();
        if (renderer instanceof DataValueRenderer) {
            if (getRowCount() > 0) {
                prepareRenderer(renderer, 0, col.getModelIndex());
            }
            Dimension p = ((DataValueRenderer) renderer).getPreferredSize();
            int prefHeight = p.height;
            int colWidth = p.width;
            if (col.getWidth() < colWidth) {
                col.setPreferredWidth(colWidth);
            }
            bestRowHeight = Math.max(bestRowHeight, prefHeight);
        }
    }
    return bestRowHeight;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) DataValueRenderer(org.knime.core.data.renderer.DataValueRenderer)

Example 47 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class TableContentView method setShowIconInColumnHeader.

/**
 * Sets the property whether or not the icon in the column header
 * shall be shown. This typically represents the column's type icon
 * (the cell type contained in the column). Sometimes, this is not
 * desired (for instance in the data outport view).
 * @param show Whether or not this icon should be shown.
 */
public final void setShowIconInColumnHeader(final boolean show) {
    if (show != m_isShowIconInColumnHeader) {
        m_isShowIconInColumnHeader = show;
        JTableHeader header = getTableHeader();
        if (header == null) {
            return;
        }
        TableCellRenderer r = header.getDefaultRenderer();
        if (r instanceof ColumnHeaderRenderer) {
            ColumnHeaderRenderer cr = (ColumnHeaderRenderer) r;
            cr.setShowIcon(show);
        }
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTableHeader(javax.swing.table.JTableHeader)

Example 48 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class TableRowHeaderView method setShowColorInfo.

/**
 * Shall row header encode the color information in an icon?
 *
 * @param isShowColor <code>true</code> for show icon (and thus the color),
 *        <code>false</code> ignore colors
 */
public void setShowColorInfo(final boolean isShowColor) {
    boolean oldValue = isShowColorInfo();
    TableCellRenderer renderer = getColumnModel().getColumn(0).getCellRenderer();
    if (renderer instanceof DataCellHeaderRenderer) {
        ((DataCellHeaderRenderer) renderer).showIcon(isShowColor);
    }
    boolean newValue = isShowColorInfo();
    m_isShowColorInfo = newValue;
    if (oldValue != newValue) {
        repaint();
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer)

Example 49 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class TableRowHeaderView method sizeWidthToFit.

// isShowColorInfo()
/**
 * Iterates all rows, determines best width and sets it. This method is expensive (as it iterates the rows).
 * @since 2.8
 */
public void sizeWidthToFit() {
    int bestFit = -1;
    int rowCount = getRowCount();
    for (int i = 0; i < rowCount; i++) {
        TableCellRenderer cellRenderer = getCellRenderer(i, 0);
        Component rendererComponent = prepareRenderer(cellRenderer, i, 0);
        bestFit = Math.max(bestFit, rendererComponent.getPreferredSize().width);
    }
    if (bestFit > 0) {
        // no idea why there are ~2 pixel missing. String is clipped if omitted.
        TableColumn column = getColumnModel().getColumn(0);
        column.setPreferredWidth(bestFit + 2);
        column.setWidth(bestFit + 2);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

Example 50 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project knime-core by knime.

the class TableRowHeaderView method updateUI.

/**
 * Changes look and feel here (by calling {@link JTable#updateUI()})
 * and also in the renderer.
 * {@inheritDoc}
 */
@Override
public void updateUI() {
    super.updateUI();
    m_headerBackground = UIManager.getColor("TableHeader.background");
    setBackground(m_headerBackground);
    Border b = UIManager.getBorder("TableHeader.border");
    TableCellRenderer renderer = getColumnModel().getColumn(0).getCellRenderer();
    if (renderer instanceof DataCellHeaderRenderer) {
        ((DataCellHeaderRenderer) renderer).setBorder(b);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) Border(javax.swing.border.Border)

Aggregations

TableCellRenderer (javax.swing.table.TableCellRenderer)122 TableColumn (javax.swing.table.TableColumn)50 Component (java.awt.Component)47 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)24 JComponent (javax.swing.JComponent)20 JTable (javax.swing.JTable)20 TableColumnModel (javax.swing.table.TableColumnModel)18 JLabel (javax.swing.JLabel)17 JTableHeader (javax.swing.table.JTableHeader)17 MouseEvent (java.awt.event.MouseEvent)11 ColumnInfo (com.intellij.util.ui.ColumnInfo)8 ActionEvent (java.awt.event.ActionEvent)8 JButton (javax.swing.JButton)8 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)8 MouseAdapter (java.awt.event.MouseAdapter)7 TableCellEditor (javax.swing.table.TableCellEditor)7 TableModel (javax.swing.table.TableModel)7 ActionListener (java.awt.event.ActionListener)6 List (java.util.List)6 JPanel (javax.swing.JPanel)6