Search in sources :

Example 16 with TableColumn

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);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) StatFacade(pcgen.facade.core.StatFacade) Dimension(java.awt.Dimension) JComponent(javax.swing.JComponent) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) TableCellUtilities(pcgen.gui2.util.table.TableCellUtilities)

Example 17 with TableColumn

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());
    }
}
Also used : TableColumn(javax.swing.table.TableColumn)

Example 18 with TableColumn

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();
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 19 with TableColumn

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();
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 20 with TableColumn

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);
    }
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Aggregations

TableColumn (javax.swing.table.TableColumn)215 TableColumnModel (javax.swing.table.TableColumnModel)66 JTable (javax.swing.JTable)44 JScrollPane (javax.swing.JScrollPane)37 JPanel (javax.swing.JPanel)31 TableCellRenderer (javax.swing.table.TableCellRenderer)30 BoxLayout (javax.swing.BoxLayout)25 JLabel (javax.swing.JLabel)24 Component (java.awt.Component)21 ActionEvent (java.awt.event.ActionEvent)20 FlowLayout (java.awt.FlowLayout)16 ActionListener (java.awt.event.ActionListener)16 DefaultCellEditor (javax.swing.DefaultCellEditor)16 JButton (javax.swing.JButton)16 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)15 JComboBox (javax.swing.JComboBox)14 Dimension (java.awt.Dimension)13 DefaultTableModel (javax.swing.table.DefaultTableModel)12 JTableHeader (javax.swing.table.JTableHeader)12 XTableColumnModel (jmri.util.swing.XTableColumnModel)12