use of javax.swing.table.TableColumn in project pcgen by PCGen.
the class StatTableModel method install.
public void install() {
table.setModel(this);
table.setDefaultRenderer(Object.class, renderer);
TableColumn abilityColumn = table.getColumn(ABILITY_COLUMN_ID);
int columnIndex = abilityColumn.getModelIndex();
int maxWidth = 0;
for (StatFacade aStat : stats) {
Component cell = renderer.getTableCellRendererComponent(table, aStat, false, false, -1, columnIndex);
maxWidth = Math.max(maxWidth, cell.getPreferredSize().width);
}
//we add some extra spacing to prevent ellipses from showing
abilityColumn.setPreferredWidth(maxWidth + 4);
TableColumn column = table.getColumn(EDITABLE_COLUMN_ID);
column.setCellRenderer(new TableCellUtilities.SpinnerRenderer());
column.setCellEditor(editor);
Dimension size = table.getPreferredSize();
size.width = table.getTableHeader().getPreferredSize().width;
JScrollPane scrollPane = (JScrollPane) table.getParent().getParent();
//we want to add room for the vertical scroll bar so it doesn't
//overlap with the table when it shows
int vbarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width;
size.width += vbarWidth;
table.setPreferredScrollableViewportSize(size);
//because of the extra viewport size in the table it will
//always look a bit off center, adding a row header to
//the scroll pane fixes this
scrollPane.setRowHeaderView(Box.createHorizontalStrut(vbarWidth));
for (StatFacade aStat : stats) {
character.getScoreBaseRef(aStat).addReferenceListener(this);
}
}
use of javax.swing.table.TableColumn in project pcgen by PCGen.
the class PrefTableColumnModel method propertyChange.
@Override
public void propertyChange(PropertyChangeEvent evt) {
super.propertyChange(evt);
String name = evt.getPropertyName();
if ("width".equals(name)) {
TableColumn col = (TableColumn) evt.getSource();
String colKey = col.getIdentifier().toString();
colWidthCtx.setInt(normalisePrefsKey(colKey), (Integer) evt.getNewValue());
}
}
use of javax.swing.table.TableColumn in project pcgen by PCGen.
the class Initiative method addColumn.
private void addColumn(String name, int width) {
DefaultTableModel tabModel = (DefaultTableModel) combatantTable.getModel();
TableColumnModel colModel = combatantTable.getColumnModel();
tabModel.addColumn(name);
TableColumn column = colModel.getColumn(colModel.getColumnCount() - 1);
column.setPreferredWidth(width);
column.setWidth(width);
column.setIdentifier(name);
columnList = getColumnOrder();
}
use of javax.swing.table.TableColumn in project pcgen by PCGen.
the class Initiative method removeColumn.
private void removeColumn(String name) {
TableColumnModel colModel = combatantTable.getColumnModel();
for (int i = 0; i < colModel.getColumnCount(); i++) {
TableColumn col = colModel.getColumn(i);
if (col.getHeaderValue().toString().equals(name)) {
colModel.removeColumn(col);
}
}
trackTable();
initTable();
columnList = getColumnOrder();
}
use of javax.swing.table.TableColumn in project SE2017_4_tuna by SE-admin.
the class Frame3 method setTableCellRenderer.
private void setTableCellRenderer(JTable todoTable, TableCellRenderer renderer) {
TableColumnModel columnModel = todoTable.getColumnModel();
int columnCount = columnModel.getColumnCount();
for (int i = 0; i < columnCount; i++) {
TableColumn column = columnModel.getColumn(i);
column.setCellRenderer(renderer);
}
}
Aggregations