use of javax.swing.table.TableColumnModel in project beast-mcmc by beast-dev.
the class SpeciesSetPanel method initTableColumn.
protected void initTableColumn() {
final TableColumnModel tableColumnModel = taxonSetsTable.getColumnModel();
TableColumn tableColumn = tableColumnModel.getColumn(0);
tableColumn.setCellRenderer(new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
tableColumn.setMinWidth(20);
tableColumn = tableColumnModel.getColumn(1);
tableColumn.setPreferredWidth(10);
}
use of javax.swing.table.TableColumnModel in project beast-mcmc by beast-dev.
the class ColumnResizer method adjustColumnPreferredWidths.
public static void adjustColumnPreferredWidths(JTable table) {
TableColumnModel columnModel = table.getColumnModel();
for (int col = 0; col < table.getColumnCount(); col++) {
int maxwidth = 0;
for (int row = 0; row < table.getRowCount(); row++) {
TableCellRenderer rend = table.getCellRenderer(row, col);
Object value = table.getValueAt(row, col);
Component comp = rend.getTableCellRendererComponent(table, value, false, false, row, col);
maxwidth = Math.max(comp.getPreferredSize().width, maxwidth);
}
// END: row loop
TableColumn column = columnModel.getColumn(col);
TableCellRenderer headerRenderer = column.getHeaderRenderer();
if (headerRenderer == null) {
headerRenderer = table.getTableHeader().getDefaultRenderer();
}
Object headerValue = column.getHeaderValue();
Component headerComp = headerRenderer.getTableCellRendererComponent(table, headerValue, false, false, 0, col);
maxwidth = Math.max(maxwidth, headerComp.getPreferredSize().width);
column.setPreferredWidth(maxwidth);
}
// END: col loop
}
use of javax.swing.table.TableColumnModel in project jgnash by ccavanaugh.
the class JTableUtils method packGenericTable.
/**
* Sizes the columns in a JTable
*
* @param table The table to size the columns in
*/
public static void packGenericTable(final JTable table) {
TableColumnModel model = table.getColumnModel();
int columns = model.getColumnCount();
for (int i = 0; i < columns; i++) {
TableColumn col = model.getColumn(i);
// Get the column header width
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
int width = comp.getPreferredSize().width;
// Find the largest width in the column
int rows = table.getRowCount();
for (int r = 0; r < rows; r++) {
renderer = table.getCellRenderer(r, i);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, i), false, false, r, i);
width = Math.max(width, comp.getPreferredSize().width);
}
// Set the column width
col.setPreferredWidth(width + MIN_WIDTH_PADDING);
}
}
use of javax.swing.table.TableColumnModel in project jgnash by ccavanaugh.
the class JTableUtils method getColumnWidths.
/**
* Returns the column widths of a table in a formatted
* {@code String}.
*
* @param table The table to collect column widths from
* @return A String in the format "34 56 56 56"
*/
public static String getColumnWidths(final JTable table) {
Objects.requireNonNull(table);
TableColumnModel model = table.getColumnModel();
int count = model.getColumnCount();
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < count; i++) {
if (i > 0) {
buffer.append(' ');
}
int index = table.convertColumnIndexToView(i);
buffer.append(model.getColumn(index).getWidth());
}
return buffer.toString();
}
use of javax.swing.table.TableColumnModel in project processdash by dtuma.
the class JTableColumnVisibilityAction method applyColumnSelections.
private void applyColumnSelections(CheckboxList list) {
TableColumnModel columnModel = table.getColumnModel();
for (int i = 0; i < list.getRowCount(); i++) {
NumberedColumn col = (NumberedColumn) list.getValueAt(i, 1);
boolean shouldBeVisible = list.getChecked(i);
if (shouldBeVisible == col.initiallyVisible)
continue;
int viewPos = table.convertColumnIndexToView(col.modelIndex);
if (shouldBeVisible && viewPos == -1) {
addColumnToModel(columnModel, col.modelIndex);
} else if (shouldBeVisible == false && viewPos != -1) {
columnModel.removeColumn(columnModel.getColumn(viewPos));
}
}
}
Aggregations