Search in sources :

Example 6 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project groovy-core by groovy.

the class ClosureRenderer method render.

private Component render() {
    if (children.isEmpty() || defaultRenderer) {
        defaultRenderer = true;
        children.clear();
        if (table != null) {
            TableCellRenderer tcr;
            if (tableHeader) {
                tcr = table.getTableHeader().getDefaultRenderer();
            } else {
                tcr = table.getDefaultRenderer(table.getColumnClass(column));
            }
            children.add(tcr.getTableCellRendererComponent(table, value, selected, focused, row, column));
        } else if (tree != null) {
            TreeCellRenderer tcr;
            tcr = new DefaultTreeCellRenderer();
            children.add(tcr.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, focused));
        } else if (list != null) {
            ListCellRenderer lcr = (ListCellRenderer) UIManager.get("List.cellRenderer");
            if (lcr == null) {
                lcr = new DefaultListCellRenderer();
            }
            children.add(lcr.getListCellRendererComponent(list, value, row, selected, focused));
        }
    }
    Object o = update.call();
    if (o instanceof Component) {
        return (Component) o;
    } else {
        return (Component) children.get(0);
    }
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 7 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project jdk8u_jdk by JetBrains.

the class bug7032791 method main.

public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new SynthLookAndFeel());
    Object value = "Test value";
    JTable table = new JTable(1, 1);
    TableCellRenderer renderer = table.getDefaultRenderer(Object.class);
    renderer.getTableCellRendererComponent(null, value, true, true, 0, 0);
    System.out.println("OK");
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) SynthLookAndFeel(javax.swing.plaf.synth.SynthLookAndFeel)

Example 8 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project pcgen by PCGen.

the class AbilityTreeTableModel method initializeTreeTable.

/**
	 * Initialise a tree table that will be backed by an AbilityTreeTableModel.
	 * @param treeTable The tree table to be initialized.
	 */
public static void initializeTreeTable(JTreeTable treeTable) {
    //$NON-NLS-1$ //$NON-NLS-2$
    treeTable.getTree().putClientProperty("JTree.lineStyle", "Horizontal");
    treeTable.setAutoCreateColumnsFromModel(false);
    DefaultTableColumnModel model = new DefaultTableColumnModel();
    TableCellRenderer headerRenderer = treeTable.getTableHeader().getDefaultRenderer();
    model.addColumn(Utilities.createTableColumn(0, "in_featSelectedAbilities", headerRenderer, //$NON-NLS-1$
    true));
    model.addColumn(//$NON-NLS-1$
    Utilities.createTableColumn(//$NON-NLS-1$
    1, //$NON-NLS-1$
    "in_featChoices", headerRenderer, true));
    treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    treeTable.setColumnModel(model);
    treeTable.setDefaultRenderer(String.class, new TableCellUtilities.AlignRenderer(SwingConstants.LEFT, true));
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) TableCellUtilities(pcgen.gui2.util.table.TableCellUtilities)

Example 9 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project SE2017_4_tuna by SE-admin.

the class UIUpdate method resizeColumnWidth.

public static void resizeColumnWidth(JTable table) {
    final TableColumnModel columnModel = table.getColumnModel();
    for (int column = 0; column < table.getColumnCount(); column++) {
        int width = 50;
        for (int row = 0; row < table.getRowCount(); row++) {
            TableCellRenderer renderer = table.getCellRenderer(row, column);
            Component comp = table.prepareRenderer(renderer, row, column);
            width = Math.max(comp.getPreferredSize().width + 1, width);
        }
        columnModel.getColumn(column).setPreferredWidth(width);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) TableColumnModel(javax.swing.table.TableColumnModel) Component(java.awt.Component)

Example 10 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.

the class AbstractTableView method reset.

public final void reset(ColumnInfo[] columnInfos, List<? extends T> data) {
    final boolean columnsChanged = myTableModel.setColumnInfos(columnInfos);
    final boolean dataChanged = !data.equals(myTableModel.getItems());
    final int oldRowCount = myTableModel.getRowCount();
    if ((dataChanged || columnsChanged) && myTable.isEditing()) {
        myTable.getCellEditor().cancelCellEditing();
    }
    if (dataChanged) {
        final int selectedRow = myTable.getSelectedRow();
        myTableModel.setItems(new ArrayList<>(data));
        if (selectedRow >= 0 && selectedRow < myTableModel.getRowCount()) {
            myTable.getSelectionModel().setSelectionInterval(selectedRow, selectedRow);
        }
    }
    myTableModel.cacheValues();
    final int rowCount = myTableModel.getRowCount();
    final int columnCount = myTableModel.getColumnCount();
    myCachedRenderers = new TableCellRenderer[rowCount][columnCount];
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            final TableCellRenderer superRenderer = myTable.getSuperCellRenderer(row, column);
            myCachedRenderers[row][column] = getTableCellRenderer(row, column, superRenderer, myTableModel.getItems().get(row));
        }
    }
    if (columnsChanged || oldRowCount == 0 && rowCount != 0) {
        adjustColumnWidths();
    }
    myTable.revalidate();
    myTable.repaint();
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer)

Aggregations

TableCellRenderer (javax.swing.table.TableCellRenderer)85 Component (java.awt.Component)30 TableColumn (javax.swing.table.TableColumn)30 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)20 JComponent (javax.swing.JComponent)12 JTable (javax.swing.JTable)12 JTableHeader (javax.swing.table.JTableHeader)12 TableColumnModel (javax.swing.table.TableColumnModel)12 MouseEvent (java.awt.event.MouseEvent)10 ColumnInfo (com.intellij.util.ui.ColumnInfo)8 JLabel (javax.swing.JLabel)8 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)8 JButton (javax.swing.JButton)7 TableCellEditor (javax.swing.table.TableCellEditor)7 ActionEvent (java.awt.event.ActionEvent)6 MouseAdapter (java.awt.event.MouseAdapter)6 List (java.util.List)6 TableModel (javax.swing.table.TableModel)6 JTextField (javax.swing.JTextField)5 ActionListener (java.awt.event.ActionListener)4