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