Search in sources :

Example 1 with DefaultTableColumnModel

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

the class AbilityTreeTableModel method initializeTreeTable.

/**
	 * Initialise a tree table that will be backed by an AbilityTreeTableModel.
	 * @param treeTable The tree table to be initialized.
	 */
public static void initializeTreeTable(JTreeTable treeTable) {
    //$NON-NLS-1$ //$NON-NLS-2$
    treeTable.getTree().putClientProperty("JTree.lineStyle", "Horizontal");
    treeTable.setAutoCreateColumnsFromModel(false);
    DefaultTableColumnModel model = new DefaultTableColumnModel();
    TableCellRenderer headerRenderer = treeTable.getTableHeader().getDefaultRenderer();
    model.addColumn(Utilities.createTableColumn(0, "in_featSelectedAbilities", headerRenderer, //$NON-NLS-1$
    true));
    model.addColumn(//$NON-NLS-1$
    Utilities.createTableColumn(//$NON-NLS-1$
    1, //$NON-NLS-1$
    "in_featChoices", headerRenderer, true));
    treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    treeTable.setColumnModel(model);
    treeTable.setDefaultRenderer(String.class, new TableCellUtilities.AlignRenderer(SwingConstants.LEFT, true));
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) TableCellUtilities(pcgen.gui2.util.table.TableCellUtilities)

Example 2 with DefaultTableColumnModel

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

the class EquipmentModel method initializeTreeTable.

public static void initializeTreeTable(JTreeTable treeTable) {
    treeTable.getTree().setRowHeight(0);
    treeTable.setFocusable(false);
    treeTable.getTree().putClientProperty("JTree.lineStyle", "Horizontal");
    normFont = treeTable.getFont();
    headerFont = FontManipulation.title(normFont);
    biggerFont = FontManipulation.title(FontManipulation.xxlarge(normFont));
    lessFont = FontManipulation.less(normFont);
    treeTable.setAutoCreateColumnsFromModel(false);
    {
        DefaultTableColumnModel model = new DefaultTableColumnModel();
        CellRenderer renderer = new CellRenderer();
        TableColumn column = new TableColumn(0);
        column.setResizable(true);
        model.addColumn(column);
        model.addColumn(createFixedColumn(1, 75, renderer));
        model.addColumn(createFixedColumn(2, 75, renderer));
        model.addColumn(createFixedColumn(3, 50, renderer));
        model.addColumn(createFixedColumn(4, 50, renderer));
        treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        treeTable.setColumnModel(model);
        treeTable.getTableHeader().setResizingAllowed(false);
    }
    treeTable.setTreeCellRenderer(new TreeRenderer());
}
Also used : DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) CharacterTreeCellRenderer(pcgen.gui2.tabs.models.CharacterTreeCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableColumn(javax.swing.table.TableColumn)

Example 3 with DefaultTableColumnModel

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

the class CompanionInfoTab method initComponents.

private void initComponents() {
    {
        DefaultTableColumnModel model = new DefaultTableColumnModel();
        TableColumn column = new TableColumn(0);
        column.setResizable(true);
        model.addColumn(column);
        column = new TableColumn(1, 120, new ButtonCellRenderer(), null);
        column.setMaxWidth(120);
        column.setResizable(false);
        model.addColumn(column);
        companionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        companionsTable.getTableHeader().setResizingAllowed(false);
        companionsTable.setAutoCreateColumnsFromModel(false);
        companionsTable.setColumnModel(model);
    }
    companionsTable.setIntercellSpacing(new Dimension(0, 0));
    companionsTable.setFocusable(false);
    companionsTable.setRowHeight(23);
    companionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    setLeftComponent(new JScrollPane(companionsTable));
    JPanel rightPane = new JPanel(new BorderLayout());
    infoPane.setOpaque(false);
    infoPane.setEditable(false);
    infoPane.setFocusable(true);
    //$NON-NLS-1$
    infoPane.setContentType("text/html");
    rightPane.add(new JScrollPane(infoPane), BorderLayout.CENTER);
    JPanel buttonPane = new JPanel(new FlowLayout());
    buttonPane.add(loadButton);
    rightPane.add(buttonPane, BorderLayout.SOUTH);
    setRightComponent(rightPane);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) BorderLayout(java.awt.BorderLayout) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn)

Example 4 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project intellij-community by JetBrains.

the class JTableWrapper method packColumns.

private void packColumns() {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) myTable.getColumnModel();
    int[] colMinWidths = new int[myColumns.length];
    for (int iColumn = 0; iColumn < myColumns.length; iColumn++) {
        TableColumn col = colModel.getColumn(iColumn);
        colMinWidths[iColumn] = col.getMinWidth();
        if (!myColumns[iColumn].needPack()) {
            col.setWidth(col.getMinWidth());
            continue;
        }
        // Get width of column header
        TableCellRenderer renderer = col.getHeaderRenderer();
        if (renderer == null) {
            renderer = myTable.getTableHeader().getDefaultRenderer();
        }
        Component comp = renderer.getTableCellRendererComponent(myTable, col.getHeaderValue(), false, false, 0, 0);
        int colWidth = comp.getPreferredSize().width;
        for (int iRow = 0; iRow < myTable.getRowCount(); iRow++) {
            renderer = myTable.getCellRenderer(iRow, iColumn);
            comp = renderer.getTableCellRendererComponent(myTable, myTable.getValueAt(iRow, iColumn), false, false, iRow, iColumn);
            colWidth = Math.max(colWidth, comp.getPreferredSize().width);
        }
        colWidth += 2 * COLUMN_HEADER_MARGIN_WIDTH;
        col.setMaxWidth(colWidth);
        col.setMinWidth(colWidth);
    }
    for (int iColumn = 0; iColumn < myColumns.length; iColumn++) {
        TableColumn col = colModel.getColumn(iColumn);
        col.setMinWidth(colMinWidths[iColumn]);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 5 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project processdash by dtuma.

the class TaskScheduleDialog method createFlatColumnModel.

private TableColumnModel createFlatColumnModel() {
    DefaultTableColumnModel result = new DefaultTableColumnModel();
    int extraWidth = 0;
    for (int i = 0; i < treeColumnModel.getColumnCount(); i++) {
        TableColumn c = treeColumnModel.getColumn(i);
        switch(c.getModelIndex()) {
            case EVTaskList.TASK_COLUMN:
            case EVTaskList.NODE_TYPE_COLUMN:
            case EVTaskList.PLAN_TIME_COLUMN:
            case EVTaskList.PLAN_DTIME_COLUMN:
            //case EVTaskList.ACT_DTIME_COLUMN:
            case EVTaskList.PLAN_DATE_COLUMN:
            case EVTaskList.REPLAN_DATE_COLUMN:
            case EVTaskList.FORECAST_DATE_COLUMN:
            case EVTaskList.MILESTONE_COLUMN:
            case EVTaskList.LABELS_COLUMN:
            case EVTaskList.NOTES_COLUMN:
            case EVTaskList.DEPENDENCIES_COLUMN:
            case EVTaskList.PCT_SPENT_COLUMN:
                result.addColumn(TableUtils.cloneTableColumn(c));
                break;
            default:
                extraWidth += c.getPreferredWidth();
                break;
        }
    }
    TableColumn c = result.getColumn(0);
    c.setPreferredWidth(c.getWidth() + extraWidth);
    return result;
}
Also used : DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point)

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