Search in sources :

Example 76 with TableColumnModel

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);
}
Also used : TableRenderer(jam.table.TableRenderer) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 77 with TableColumnModel

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
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) TableColumnModel(javax.swing.table.TableColumnModel) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

Example 78 with TableColumnModel

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);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) TableColumnModel(javax.swing.table.TableColumnModel) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

Example 79 with TableColumnModel

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();
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel)

Example 80 with TableColumnModel

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));
        }
    }
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel)

Aggregations

TableColumnModel (javax.swing.table.TableColumnModel)168 TableColumn (javax.swing.table.TableColumn)66 JTable (javax.swing.JTable)34 JScrollPane (javax.swing.JScrollPane)31 JButton (javax.swing.JButton)30 BoxLayout (javax.swing.BoxLayout)24 TableCellEditor (javax.swing.table.TableCellEditor)23 ButtonEditor (jmri.util.table.ButtonEditor)23 ButtonRenderer (jmri.util.table.ButtonRenderer)23 JLabel (javax.swing.JLabel)22 JPanel (javax.swing.JPanel)22 ActionEvent (java.awt.event.ActionEvent)20 ActionListener (java.awt.event.ActionListener)16 FlowLayout (java.awt.FlowLayout)15 Border (javax.swing.border.Border)13 Iterator (java.util.Iterator)12 Set (java.util.Set)12 JTableHeader (javax.swing.table.JTableHeader)12 TableCellRenderer (javax.swing.table.TableCellRenderer)12 Container (java.awt.Container)10