Search in sources :

Example 11 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project java-swing-tips by aterai.

the class FocusAncestorListener method initialize.

@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder encoder) {
    super.initialize(type, oldInstance, newInstance, encoder);
    DefaultTableColumnModel m = (DefaultTableColumnModel) oldInstance;
    for (int col = 0; col < m.getColumnCount(); col++) {
        encoder.writeStatement(getAddColumn(oldInstance, m.getColumn(col)));
    }
}
Also used : DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel)

Example 12 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project gitblit by gitblit.

the class Utils method packColumn.

// Sets the preferred width of the visible column specified by vColIndex.
// The column will be just wide enough to show the column head and the
// widest cell in the column. margin pixels are added to the left and right
// (resulting in an additional width of 2*margin pixels).
private static void packColumn(JTable table, int vColIndex, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width = 0;
    // Get width of column header
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
        renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;
    // Get maximum width of column data
    for (int r = 0; r < table.getRowCount(); r++) {
        renderer = table.getCellRenderer(r, vColIndex);
        comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
        width = Math.max(width, comp.getPreferredSize().width);
    }
    // Add margin
    width += 2 * margin;
    // Set the width
    col.setPreferredWidth(width);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

Example 13 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project pcgen by PCGen.

the class ClassLevelTableModel method initializeTable.

public static void initializeTable(JTable classLevelTable) {
    JTableHeader tableHeader = classLevelTable.getTableHeader();
    tableHeader.setResizingAllowed(false);
    tableHeader.setReorderingAllowed(false);
    TableColumnModel columnModel = new DefaultTableColumnModel();
    TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
    columnModel.addColumn(Utilities.createTableColumn(0, "Level", headerRenderer, false));
    columnModel.addColumn(Utilities.createTableColumn(1, "HP", headerRenderer, false));
    columnModel.addColumn(Utilities.createTableColumn(2, "Class (All Levels In Class)", headerRenderer, true));
    classLevelTable.setColumnModel(columnModel);
    classLevelTable.setAutoCreateColumnsFromModel(false);
    classLevelTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    classLevelTable.setFocusable(false);
    classLevelTable.setCellSelectionEnabled(false);
    classLevelTable.setRowHeight(20);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel)

Example 14 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project pcgen by PCGen.

the class StatTableModel method initializeTable.

public static void initializeTable(JTable statsTable) {
    JTableHeader tableHeader = statsTable.getTableHeader();
    tableHeader.setResizingAllowed(false);
    tableHeader.setReorderingAllowed(false);
    statsTable.setAutoCreateColumnsFromModel(false);
    DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
    {
        TableColumn column = Utilities.createTableColumn(ABILITY_NAME, "Ability", new AbilityHeaderCellRenderer(), true);
        column.setIdentifier(ABILITY_COLUMN_ID);
        columnModel.addColumn(column);
        String htmlText = "<html><div align=\"center\">Final<br>Score</div></html>";
        column = Utilities.createTableColumn(FINAL_ABILITY_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText), false);
        column.setCellRenderer(new ValueRenderer());
        columnModel.addColumn(column);
        TableCellRenderer renderer = new ModRenderer();
        htmlText = "<html><div align=\"center\">Ability<br>Mod</div></html>";
        column = Utilities.createTableColumn(ABILITY_MOD, htmlText, new FixedHeaderCellRenderer(htmlText), false);
        column.setCellRenderer(renderer);
        columnModel.addColumn(column);
        htmlText = "<html><div align=\"center\">Editable<br>Score</div></html>";
        column = Utilities.createTableColumn(EDITABLE_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText), false);
        column.setIdentifier(EDITABLE_COLUMN_ID);
        columnModel.addColumn(column);
        htmlText = "<html><div align=\"center\">Race<br>Adj</div></html>";
        column = Utilities.createTableColumn(RACE_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
        column.setCellRenderer(renderer);
        columnModel.addColumn(column);
        htmlText = "<html><div align=\"center\">Misc<br>Adj</div></html>";
        column = Utilities.createTableColumn(MISC_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
        column.setCellRenderer(renderer);
        columnModel.addColumn(column);
    }
    statsTable.setColumnModel(columnModel);
    statsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    statsTable.setShowVerticalLines(false);
    statsTable.setCellSelectionEnabled(false);
    statsTable.setFocusable(false);
    // XXX this should be calculated relative to font size and the size of a jspinner
    statsTable.setRowHeight(27);
    statsTable.setOpaque(false);
    tableHeader.setFont(FontManipulation.title(statsTable.getFont()));
    FontManipulation.large(statsTable);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) JTableHeader(javax.swing.table.JTableHeader) TableColumn(javax.swing.table.TableColumn)

Example 15 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project pcgen by PCGen.

the class SkillCostTableModel method initializeTable.

public static void initializeTable(JTable table) {
    table.setAutoCreateColumnsFromModel(false);
    JTableHeader header = table.getTableHeader();
    TableColumnModel columns = new DefaultTableColumnModel();
    TableCellRenderer headerRenderer = header.getDefaultRenderer();
    columns.addColumn(Utilities.createTableColumn(0, //$NON-NLS-1$
    LanguageBundle.getString("in_skillSkillCost"), headerRenderer, true));
    columns.addColumn(Utilities.createTableColumn(1, //$NON-NLS-1$
    LanguageBundle.getString("in_skillRankCost"), headerRenderer, false));
    columns.addColumn(Utilities.createTableColumn(2, //$NON-NLS-1$
    LanguageBundle.getString("in_skillMaxRanks"), headerRenderer, false));
    table.setColumnModel(columns);
    table.setFocusable(false);
    table.setCellSelectionEnabled(false);
    header.setReorderingAllowed(false);
    header.setResizingAllowed(false);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel)

Aggregations

DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)25 TableColumn (javax.swing.table.TableColumn)18 TableCellRenderer (javax.swing.table.TableCellRenderer)11 TableColumnModel (javax.swing.table.TableColumnModel)8 Component (java.awt.Component)6 JTableHeader (javax.swing.table.JTableHeader)6 JTable (javax.swing.JTable)5 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)5 JScrollPane (javax.swing.JScrollPane)4 DefaultTableModel (javax.swing.table.DefaultTableModel)4 Color (java.awt.Color)3 GridBagConstraints (java.awt.GridBagConstraints)3 LineBorder (javax.swing.border.LineBorder)3 Insets (java.awt.Insets)2 ComponentAdapter (java.awt.event.ComponentAdapter)2 ComponentEvent (java.awt.event.ComponentEvent)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 DecimalFormat (java.text.DecimalFormat)2 TableCellUtilities (pcgen.gui2.util.table.TableCellUtilities)2