Search in sources :

Example 66 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project EnrichmentMapApp by BaderLab.

the class HeatMapMainPanel method clearTableHeader.

private void clearTableHeader() {
    JTableHeader header = table.getTableHeader();
    TableColumnModel columnModel = table.getColumnModel();
    if (columnModel.getColumnCount() > 0) {
        TableColumn rankColumn = columnModel.getColumn(HeatMapTableModel.RANK_COL);
        TableCellRenderer existingRenderer = rankColumn.getHeaderRenderer();
        if (existingRenderer instanceof ColumnHeaderRankOptionRenderer) {
            ((ColumnHeaderRankOptionRenderer) existingRenderer).dispose(header);
        }
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) ColumnHeaderRankOptionRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColumnHeaderRankOptionRenderer) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 67 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project groovy by apache.

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 68 with TableCellRenderer

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

the class IconPickerDialogTest method tableToString.

@NotNull
public static String tableToString(@NotNull JTable table, int startRow, int endRow, int startColumn, int endColumn, int cellWidth) {
    StringBuilder sb = new StringBuilder();
    String formatString = "%-" + Integer.toString(cellWidth) + "s";
    for (int row = Math.max(0, startRow); row < Math.min(endRow, table.getRowCount()); row++) {
        for (int column = Math.max(0, startColumn); column < Math.min(table.getColumnCount(), endColumn); column++) {
            Object value = table.getValueAt(row, column);
            TableCellRenderer renderer = table.getCellRenderer(row, column);
            Component component = renderer.getTableCellRendererComponent(table, value, false, false, row, column);
            DefaultTableCellRenderer label = (DefaultTableCellRenderer) component;
            assertThat(label.getText()).isEmpty();
            String cell = label.getAccessibleContext().getAccessibleName();
            if (cell.length() > cellWidth) {
                cell = cell.substring(0, cellWidth - 3) + "...";
            }
            sb.append(String.format(formatString, cell));
        }
        sb.append('\n');
    }
    return sb.toString();
}
Also used : DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with TableCellRenderer

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

the class EditableTreeTable method getCellRenderer.

// copied from TableView
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    ListTreeTableModelOnColumns model = (ListTreeTableModelOnColumns) getTableModel();
    ColumnInfo columnInfo = model.getColumnInfos()[convertColumnIndexToModel(column)];
    T item = (T) getValueAt(convertRowIndexToModel(row), 0);
    final TableCellRenderer renderer = columnInfo.getCustomizedRenderer(item, columnInfo.getRenderer(item));
    return renderer == null ? super.getCellRenderer(row, column) : renderer;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) ColumnInfo(com.intellij.util.ui.ColumnInfo)

Example 70 with TableCellRenderer

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

the class InjectionsSettingsUI method createLanguageCellRenderer.

private static TableCellRenderer createLanguageCellRenderer() {
    return new TableCellRenderer() {

        final JLabel myLabel = new JLabel();

        public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
            final InjInfo injection = (InjInfo) value;
            // fix for a marvellous Swing peculiarity: AccessibleJTable likes to pass null here
            if (injection == null)
                return myLabel;
            final String languageId = injection.injection.getInjectedLanguageId();
            final Language language = InjectedLanguage.findLanguageById(languageId);
            final FileType fileType = language == null ? null : language.getAssociatedFileType();
            myLabel.setIcon(fileType == null ? null : fileType.getIcon());
            myLabel.setText(language == null ? languageId : language.getDisplayName());
            setLabelColors(myLabel, table, isSelected, row);
            return myLabel;
        }
    };
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) Language(com.intellij.lang.Language) InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) FileType(com.intellij.openapi.fileTypes.FileType)

Aggregations

TableCellRenderer (javax.swing.table.TableCellRenderer)122 TableColumn (javax.swing.table.TableColumn)50 Component (java.awt.Component)47 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)24 JComponent (javax.swing.JComponent)20 JTable (javax.swing.JTable)20 TableColumnModel (javax.swing.table.TableColumnModel)18 JLabel (javax.swing.JLabel)17 JTableHeader (javax.swing.table.JTableHeader)17 MouseEvent (java.awt.event.MouseEvent)11 ColumnInfo (com.intellij.util.ui.ColumnInfo)8 ActionEvent (java.awt.event.ActionEvent)8 JButton (javax.swing.JButton)8 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)8 MouseAdapter (java.awt.event.MouseAdapter)7 TableCellEditor (javax.swing.table.TableCellEditor)7 TableModel (javax.swing.table.TableModel)7 ActionListener (java.awt.event.ActionListener)6 List (java.util.List)6 JPanel (javax.swing.JPanel)6