use of javax.swing.table.JTableHeader in project knime-base by knime.
the class PreviewTableContentView method onMouseClickInHeader.
/**
* {@inheritDoc}
*/
@Override
protected void onMouseClickInHeader(final MouseEvent e) {
JTableHeader header = getTableHeader();
// get column in which event occurred
int column = header.columnAtPoint(e.getPoint());
if (column < 0) {
return;
}
int modelIndex = convertColumnIndexToModel(column);
firePropertyChange(PROPERTY_SPEC_CHANGED, null, modelIndex);
}
use of javax.swing.table.JTableHeader in project knime-base by knime.
the class PMCCNodeView method changeRenderer.
private void changeRenderer(final String renderer) {
TableContentView tcv = m_tableView.getContentTable();
tcv.changeRenderer(DoubleCell.TYPE, renderer);
Component c = m_tableView.getCorner(JScrollPane.UPPER_LEFT_CORNER);
LegendCornerAll cornerRenderer = null;
if (c instanceof JTableHeader) {
JTableHeader corner = (JTableHeader) c;
TableCellRenderer ren = corner.getDefaultRenderer();
if (ren instanceof LegendCornerAll) {
cornerRenderer = (LegendCornerAll) ren;
}
}
if (cornerRenderer != null) {
if (renderer.equals(ColorRender.DESCRIPTION)) {
cornerRenderer.setPaintLegend(true);
// no need to set column header height, done by label UI
tcv.setColumnWidth(15);
TableCellRenderer r = m_tableView.getContentTable().getTableHeader().getDefaultRenderer();
if (r instanceof JLabel) {
((JLabel) r).setUI(new VerticalLabelUI());
}
} else {
cornerRenderer.setPaintLegend(false);
m_tableView.setColumnHeaderViewHeight(16);
tcv.setColumnWidth(75);
TableCellRenderer r = m_tableView.getContentTable().getTableHeader().getDefaultRenderer();
if (r instanceof JLabel) {
((JLabel) r).updateUI();
}
}
}
m_currentRendererID = renderer;
}
use of javax.swing.table.JTableHeader in project knetbuilder by Rothamsted.
the class ResultTableUtil method calcColumnWidths.
/**
* Calculates and sets the width distribution of columns in a given JTable.
*
* @param table - JTable
*/
public static void calcColumnWidths(JTable table) {
// get table header and renderer
JTableHeader header = table.getTableHeader();
TableCellRenderer defaultHeaderRenderer = null;
if (header != null)
defaultHeaderRenderer = header.getDefaultRenderer();
TableColumnModel columns = table.getColumnModel();
TableModel data = table.getModel();
int margin = columns.getColumnMargin();
int rowCount = data.getRowCount();
int totalWidth = 0;
// go through all columns
for (int i = columns.getColumnCount() - 1; i >= 0; --i) {
// get current column
TableColumn column = columns.getColumn(i);
int columnIndex = column.getModelIndex();
int width = -1;
// get header for current column
TableCellRenderer h = column.getHeaderRenderer();
if (h == null)
h = defaultHeaderRenderer;
if (h != null) {
// Not explicitly impossible
Component c = h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, i);
// get header width
width = (int) (c.getPreferredSize().width * 1.1);
}
// go through all rows
for (int row = rowCount - 1; row >= 0; --row) {
TableCellRenderer r = table.getCellRenderer(row, i);
Component c = r.getTableCellRendererComponent(table, data.getValueAt(row, columnIndex), false, false, row, i);
// max of header width and actual component width
width = Math.max(width, c.getPreferredSize().width);
}
if (width > 200)
width = 200;
if (width >= 0)
column.setPreferredWidth(width + margin);
// setting and summing preferred width of each column
totalWidth += column.getPreferredWidth();
}
// set width to table
Dimension size = table.getPreferredScrollableViewportSize();
size.width = totalWidth;
table.setPreferredScrollableViewportSize(size);
}
use of javax.swing.table.JTableHeader in project com.revolsys.open by revolsys.
the class JTableUtil method sizeColumnsToFit.
public static void sizeColumnsToFit(final JTable table) {
Invoke.later(() -> {
final JTableHeader tableHeader = table.getTableHeader();
final TableColumnModel columnModel = table.getColumnModel();
for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) {
final TableColumn column = columnModel.getColumn(columnIndex);
final String columnName = table.getColumnName(columnIndex);
final TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
final int headerWidth = headerRenderer.getTableCellRendererComponent(table, columnName, false, false, 0, 0).getPreferredSize().width;
int maxwidth = headerWidth + 20;
for (int rowIndex = 0; rowIndex < table.getRowCount(); rowIndex++) {
final TableCellRenderer cellRenderer = table.getCellRenderer(rowIndex, columnIndex);
final Object value = table.getValueAt(rowIndex, columnIndex);
final Component component = cellRenderer.getTableCellRendererComponent(table, value, false, false, rowIndex, columnIndex);
maxwidth = Math.max(component.getPreferredSize().width, maxwidth);
}
column.setPreferredWidth(maxwidth + 5);
}
});
}
use of javax.swing.table.JTableHeader in project com.revolsys.open by revolsys.
the class SingleRecordTableModel method newTable.
public static BaseJTable newTable(final Record object, final boolean editable) {
final SingleRecordTableModel model = new SingleRecordTableModel(object, editable);
final BaseJTable table = newTable(model);
final JTableHeader tableHeader = table.getTableHeader();
tableHeader.setReorderingAllowed(false);
return table;
}
Aggregations