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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations