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;
}
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);
}
}
}
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();
}
}
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);
}
}
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);
}
}
Aggregations