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