Search in sources :

Example 6 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)

Example 7 with DefaultTableColumnModel

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

the class WBSTabPanel method copyColumnsDeep.

private TableColumnModel copyColumnsDeep(TableColumnModel tableColumnModel) {
    TableColumnModel newTableColumnModel = new DefaultTableColumnModel();
    for (Enumeration columns = tableColumnModel.getColumns(); columns.hasMoreElements(); ) {
        DataTableColumn existingColumn = (DataTableColumn) columns.nextElement();
        newTableColumnModel.addColumn(new DataTableColumn(existingColumn));
    }
    return newTableColumnModel;
}
Also used : Enumeration(java.util.Enumeration) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) TableColumnModel(javax.swing.table.TableColumnModel) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel)

Example 8 with DefaultTableColumnModel

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

the class TaskScheduleDialog method changeTreeTableModel.

protected void changeTreeTableModel(TreeTableModel m, TableColumnModel columnModel) {
    // changing the TreeTableModel below causes our column model to
    // be completely recreated from scratch.  Unfortunately, this
    // loses all information about column width, tooltips, etc.  To
    // avoid this, we temporarily install a discardable column model.
    // The disruptive changes will be made to it, then we reinstall
    // the desired column model when we're done.
    //    Note that we can do this only because we know that we'll
    // be replacing the TreeTableModel with another one that is
    // exactly compatible.
    treeTable.setColumnModel(new DefaultTableColumnModel());
    treeTable.setTreeTableModel(m);
    treeTable.setColumnModel(columnModel);
}
Also used : DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel)

Example 9 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project mafscaling by vimsh.

the class ClosedLoop method createAfrDataTable.

private JTable createAfrDataTable(JPanel panel, String tableName, int gridy) {
    final JTable afrTable = new JTable() {

        private static final long serialVersionUID = 6526901361175099297L;

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    DefaultTableColumnModel afrModel = new DefaultTableColumnModel();
    final TableColumn afrColumn = new TableColumn(0, 250);
    afrColumn.setHeaderValue(tableName);
    afrModel.addColumn(afrColumn);
    JTableHeader lblAfrTableName = afrTable.getTableHeader();
    lblAfrTableName.setColumnModel(afrModel);
    lblAfrTableName.setReorderingAllowed(false);
    DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblAfrTableName.getDefaultRenderer();
    headerRenderer.setHorizontalAlignment(SwingConstants.LEFT);
    GridBagConstraints gbc_lblAfrTableName = new GridBagConstraints();
    gbc_lblAfrTableName.insets = new Insets((gridy == 0 ? 0 : 5), 0, 0, 0);
    gbc_lblAfrTableName.anchor = GridBagConstraints.PAGE_START;
    gbc_lblAfrTableName.fill = GridBagConstraints.HORIZONTAL;
    gbc_lblAfrTableName.gridx = 0;
    gbc_lblAfrTableName.gridy = gridy;
    panel.add(lblAfrTableName, gbc_lblAfrTableName);
    afrTable.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            afrColumn.setWidth(afrTable.getWidth());
        }
    });
    afrTable.getTableHeader().setReorderingAllowed(false);
    afrTable.setColumnSelectionAllowed(true);
    afrTable.setCellSelectionEnabled(true);
    afrTable.setBorder(new LineBorder(new Color(0, 0, 0)));
    afrTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    afrTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    afrTable.setModel(new DefaultTableModel(AfrTableRowCount, AfrTableColumnCount));
    Utils.initializeTable(afrTable, ColumnWidth);
    if (tableName.equals(Afr1TableName)) {
        Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") } };
        NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class);
        renderer.setFormats(formatMatrix);
    } else if (tableName.equals(Afr2TableName)) {
        Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") }, { new DecimalFormat("#"), new DecimalFormat("#") } };
        NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class);
        renderer.setFormats(formatMatrix);
    }
    GridBagConstraints gbc_afrTable = new GridBagConstraints();
    gbc_afrTable.insets = new Insets(0, 0, 0, 0);
    gbc_afrTable.anchor = GridBagConstraints.PAGE_START;
    gbc_afrTable.gridx = 0;
    gbc_afrTable.gridy = gridy + 1;
    panel.add(afrTable, gbc_afrTable);
    excelAdapter.addTable(afrTable, true, false);
    return afrTable;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) LineBorder(javax.swing.border.LineBorder) Color(java.awt.Color) DefaultTableModel(javax.swing.table.DefaultTableModel) DecimalFormat(java.text.DecimalFormat) JTableHeader(javax.swing.table.JTableHeader) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Format(java.text.Format) DecimalFormat(java.text.DecimalFormat) JTable(javax.swing.JTable) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 10 with DefaultTableColumnModel

use of javax.swing.table.DefaultTableColumnModel in project mafscaling by vimsh.

the class BilinearInterpolator method adjustColumnSizes.

/**
 * Method sets columns width to the widest value
 * @param table
 * @param column
 * @param margin
 */
public static void adjustColumnSizes(JTable table, int column, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(column);
    int width;
    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;
    for (int r = 0; r < table.getRowCount(); ++r) {
        renderer = table.getCellRenderer(r, column);
        comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, column), false, false, r, column);
        int currentWidth = comp.getPreferredSize().width;
        width = Math.max(width, currentWidth);
    }
    width += 2 * margin;
    col.setPreferredWidth(width);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

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