Java 类javax.swing.table.TableCellRenderer 实例源码

项目:VASSAL-src    文件:TranslateWindow.java   
public TableCellRenderer getCellRenderer(int row, int column) {
  TableColumn tableColumn = getColumnModel().getColumn(column);
  TableCellRenderer renderer = tableColumn.getCellRenderer();
  if (renderer == null) {
    Class<?> c = getColumnClass(column);
    if( c.equals(Object.class) )
    {
      Object o = getValueAt(row,column);
      if( o != null )
        c = getValueAt(row,column).getClass();
    }
    renderer = getDefaultRenderer(c);
  }
  return renderer;
}
项目:javaportfolio    文件:PortfolioTable.java   
public TableCellRenderer getCellRenderer(int row, int column) {

        int modelRow = getRowSorter().convertRowIndexToModel(row);
        Double profitPercentage = (Double) getModel().getValueAt(modelRow, 12);
        String name = (String) getModel().getValueAt(modelRow, 0);
        name = name + " " + portfolio.getTicker(name);
        if (profitPercentage != null) {
            if (profitPercentage < -10.0) {
                return new CellRenderer(java.awt.Color.RED, (column != 0), name);

            } else if (profitPercentage < 10.0) {
                return new CellRenderer(java.awt.Color.YELLOW, (column != 0), name);
            }
        }
        // return super.getCellRenderer(row, column);
        return new CellRenderer(java.awt.Color.GREEN, (column != 0), (column == 0)?name:null);

    }
项目:incubator-netbeans    文件:BaseTable.java   
/** Overridden to hide the selection when not focused, and paint across the
 * selected row if focused. */
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
    Object value = getValueAt(row, col);

    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();

    boolean isSelected = isSelected(row, focusOwner);

    Component result = renderer.getTableCellRendererComponent(this, value, isSelected, false, row, col);

    if( PropUtils.isNimbus ) {
        //HACK to get rid of alternate row background colors
        if( !isSelected ) {
            Color bkColor = getBackground();
            if( null != bkColor ) 
                result.setBackground( new Color( bkColor.getRGB() ) );
        }
    }

    return result;
}
项目:incubator-netbeans    文件:JXTableDecorator.java   
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    boolean selected = false;
    for(int i: getSelectedRows()) {
        if(row == i) {
            selected = true;
            break;
        }
    }
    Component c = super.prepareRenderer(renderer, row, column);
    if(selected) {
        c.setBackground(getSelectionBackground());
    } else {
        c.setBackground(backgroundColorForRow(row));
    }
    return c;
}
项目:incubator-netbeans    文件:DataViewTableUI.java   
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    Component c = super.prepareRenderer(renderer, row, column);
    if (getModel().hasUpdates(
            convertRowIndexToModel(row),
            convertColumnIndexToModel(column))) {

        Color color = isCellSelected(row, column) ? selectedForeground : unselectedForeground;

        if (c instanceof JCheckBox) {
            checkboxReplacement.removeAll();
            checkboxReplacement.setBorder(new LineBorder(color, borderThickness));
            checkboxReplacement.add(c);
            return checkboxReplacement;
        } else {
            c.setForeground(color);
            return c;
        }
    }
    return c;
}
项目:incubator-netbeans    文件:Outline.java   
/**
 * Configure the cell editor.
 * This method allows to override the configuration of cell editor when cell editing is initiated.
 * 
 * @param editor The editor component
 * @param row Editor's row
 * @param column Editor's column
 */
protected void configureTreeCellEditor( Component editor, int row, int column ) {
    if( !(editor instanceof JComponent) ) {
        return;
    }
    TreeCellEditorBorder b = new TreeCellEditorBorder();
    TreePath path = getLayoutCache().getPathForRow(convertRowIndexToModel(row));
    Object o = getValueAt(row, column);
    RenderDataProvider rdp = getRenderDataProvider();
    TableCellRenderer tcr = getDefaultRenderer(Object.class);
    if (rdp instanceof CheckRenderDataProvider && tcr instanceof DefaultOutlineCellRenderer) {
        CheckRenderDataProvider crender = (CheckRenderDataProvider) rdp;
        DefaultOutlineCellRenderer ocr = (DefaultOutlineCellRenderer) tcr;
        Object value = getValueAt(row, column);
        if (value != null && crender.isCheckable(value) && crender.isCheckEnabled(value)) {
            b.checkWidth = ocr.getTheCheckBoxWidth();
            b.checkBox = ocr.setUpCheckBox(crender, value, ocr.createCheckBox());
        }
    }
    b.icon = rdp.getIcon(o);
    b.nestingDepth = Math.max( 0, path.getPathCount() - (isRootVisible() ? 1 : 2) );
    b.isLeaf = getOutlineModel().isLeaf(o);
    b.isExpanded = getLayoutCache().isExpanded(path);

    ((JComponent)editor).setBorder(b);
}
项目:jdk8u-jdk    文件:OldJTable.java   
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
项目:incubator-netbeans    文件:ETableHeader.java   
/**
 * Get the table header renderer for the particular column.
 * If the column is {@link ETableColumn}, check createDefaultHeaderRenderer()
 * method. If it's not overridden, use the current header renderer.
 * If it is overridden, set the current header renderer to the base
 * column's renderer. If the overridden renderer delegates to the original,
 * it will get this header renderer ({@link #headerRendererUI}).
 * @param tc The column
 * @return the renderer
 */
private TableCellRenderer getColumnHeaderRenderer(TableColumn tc) {
    if (tc instanceof ETableColumn) {
        ETableColumn eColumn = (ETableColumn) tc;
        TableCellRenderer columnHeaderRenderer;
        if (!defaultColumnHeaderRenderers.containsKey(eColumn)) {
            TableCellRenderer tcr = eColumn.createDefaultHeaderRenderer();
            if (tcr instanceof ETableColumn.ETableColumnHeaderRendererDelegate) {
                defaultColumnHeaderRenderers.put(eColumn, null);
                columnHeaderRenderer = null;
            } else {
                eColumn.setTableHeaderRendererDelegate(headerRendererUI);
                columnHeaderRenderer = tcr;
            }
        } else {
            columnHeaderRenderer = defaultColumnHeaderRenderers.get(eColumn);
        }
        if (columnHeaderRenderer != null) {
            return columnHeaderRenderer;
        } else {
            return headerRendererUI;
        }
    } else {
        return headerRendererUI;
    }
}
项目:incubator-netbeans    文件:DocumentSwitcherTable.java   
@Override
public Component prepareRenderer( TableCellRenderer renderer, int row, int column ) {
    SwitcherTableItem item = (SwitcherTableItem) getModel().getValueAt(row, column);

    boolean selected = row == getSelectedRow() &&
            column == getSelectedColumn() && item != null;        

    Component renComponent = super.prepareRenderer( renderer, row, column );
    if( selected && isClosable( (Item) item) ) {
        if( renComponent instanceof JLabel ) {
            String text = ((JLabel)renComponent).getText();
            if( text.endsWith(" ←") ) { //NOI18N
                text = text.substring(0, text.length()-2);
                ((JLabel)renComponent).setText(text);
            }
        }
        JPanel res = new JPanel( new BorderLayout(0, 0) );
        res.add( renComponent, BorderLayout.CENTER );
        res.add( btnClose, BorderLayout.EAST );
        res.setBackground( renComponent.getBackground() );
        return res;
    }
    return renComponent;
}
项目:Wilmersdorf_SER316    文件:JNCalendar.java   
public TableCellRenderer getCellRenderer(int row, int column) {
    Object d = this.getModel().getValueAt(row, column);
    /*
     * if (d != null) return new JNCalendarCellRenderer( new
     * CalendarDate(new Integer(d.toString()).intValue(), _date.getMonth(),
     * _date.getYear()));
     */
    if (d != null)
        renderer.setDate(
            new CalendarDate(
                new Integer(d.toString()).intValue(),
                _date.getMonth(),
                _date.getYear()));
    else
        renderer.setDate(null);
    return renderer;
}
项目:incubator-netbeans    文件:UIUtilities.java   
/**
 * Initializes preferred (and eventually maximum) width of a table column
 * based on the size of its header and the estimated longest value.
 *
 * @param table Table to adjust the column width for.
 * @param index Index of the column.
 * @param longValue Estimated long value for the column.
 * @param padding Number of pixes for padding.
 */
public static void initColumnWidth(JTable table, int index, Object longValue, int padding) {
    TableColumn column = table.getColumnModel().getColumn(index);

    // get preferred size of the header
    TableCellRenderer headerRenderer = column.getHeaderRenderer();
    if (headerRenderer == null) {
        headerRenderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp = headerRenderer.getTableCellRendererComponent(
            table, column.getHeaderValue(), false, false, 0, 0);
    int width = comp.getPreferredSize().width;

    // get preferred size of the long value (remeber max of the pref. size for header and long value)
    comp = table.getDefaultRenderer(table.getModel().getColumnClass(index)).getTableCellRendererComponent(
            table, longValue, false, false, 0, index);
    width = Math.max(width, comp.getPreferredSize().width) + 2 * padding;

    // set preferred width of the column
    column.setPreferredWidth(width);
    // if the column contains boolean values, the preferred width
    // should also be its max width
    if (longValue instanceof Boolean) {
        column.setMaxWidth(width);
    }
}
项目:ramus    文件:PriceEditComponent.java   
@Override
public Component getTableCellRendererComponent(JTable table,
                                               Object value, boolean isSelected, boolean hasFocus, int row,
                                               int column) {
    Component component = super.getTableCellRendererComponent(table,
            value, isSelected, hasFocus, row, column);
    if (value != null) {
        if (component instanceof JLabel)
            ((JLabel) component)
                    .setText(DateAttributePlugin.DATE_INSTANCE
                            .format(value));
        else {
            TableCellRenderer renderer = table
                    .getDefaultRenderer(Date.class);
            return renderer.getTableCellRendererComponent(table, value,
                    isSelected, hasFocus, row, column);
        }
    }
    return component;
}
项目:jmt    文件:StationsPanel.java   
/**Returns combobox-styled cellrenderer if a multiple choice cell is to be rendered.
 * @return cell renderer*/
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    //if this is type column, I must render it as a combo box instead of a jtextfield
    if (column == 1) {
        if (isLdEnabled()) {
            return LD_enabled_StationTypeCell;
        } else {
            return LD_disabled_StationTypeCell;
        }
    } else if (column == getColumnCount() - 1) {
        return deleteButtonCellRenderer;
    } else {
        return new DefaultTableCellRenderer();
    }
}
项目:incubator-netbeans    文件:DelegatingCellRenderer.java   
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Outline outline = (Outline) table;
    Node n = getNodeAt(outline, row);
    if (n instanceof TreeModelNode) {
        TreeModelNode tmn = (TreeModelNode) n;
        TableRendererModel trm = tmn.getModel();
        try {
            if (trm.canRenderCell(tmn.getObject(), columnID)) {
                TableCellRenderer renderer = trm.getCellRenderer(tmn.getObject(), columnID);
                if (renderer != null) {
                    return renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
            }
        } catch (UnknownTypeException ex) {
        }
    }
    // No specific renderer
    return defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
项目:OpenJSharp    文件:OldJTable.java   
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
项目:QN-ACTR-Release    文件:StationsPanel.java   
/**Returns combobox-styled cellrenderer if a multiple choice cell is to be rendered.
 * @return cell renderer*/
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    //if this is type column, I must render it as a combo box instead of a jtextfield
    if (column == 1) {
        if (LD_enabled_system) {
            return LD_enabled_StationTypeCell;
        } else {
            return LD_disabled_StationTypeCell;
        }
    } else if (column == getColumnCount() - 1) {
        return deleteButtonCellRenderer;
    } else {
        return new DefaultTableCellRenderer();
    }
}
项目:QN-ACTR-Release    文件:ClassesPanel.java   
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if (column == 1) {
        return comboEditor.getRenderer();
    } else if (column == 5) {
        /*if distribution column contains null value, no editor must be displayed,
        as this class is a closed one (e.g. described by population)*/
        if (getValueAt(row, column - 1) != null) {
            return new ButtonCellEditor(editDistributionButton);
        } else {
            return getDefaultRenderer(String.class);
        }
    }
    //Addition of column that contains delete buttons
    if (column == 6) {
        return new ButtonCellEditor(deleteButton);
    } else {
        return getDefaultRenderer(getModel().getColumnClass(column));
    }
}
项目:ViolenciaContraMulher    文件:FormataTamanhoColunasJTable.java   
private static void packColumn(JTable table, int vColIndex, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.
            getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width;            // Obtém a largura do cabeçalho da coluna
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
        renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp = renderer.getTableCellRendererComponent(
            table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;            // Obtém a largura maxima da coluna de dados
    for (int r = 0; r < table.getRowCount(); r++) {
        renderer = table.getCellRenderer(r, vColIndex);
        comp = renderer.getTableCellRendererComponent(
                table, table.getValueAt(r, vColIndex), false, false, r,
                vColIndex);
        width = Math.max(width, comp.getPreferredSize().width);
    }
    width += 2 * margin;            // Configura a largura
    col.setPreferredWidth(width);
}
项目:QN-ACTR-Release    文件:jmodelClassesPanel.java   
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if (column == 0) {
        return new ColorCellEditor();
    } else if (column == 2) {
        return super.getCellRenderer(row, 1);
    } else if (column == 6) {
        /*if distribution column contains null value, no editor must be displayed,
        as this class is a closed one (e.g. described by population)*/
        if (getValueAt(row, column - 1) != null) {
            return new ButtonCellEditor(editDistributionButton);
        } else {
            return getDefaultRenderer(String.class);
        }
    }
    // Column for refercence source
    else if (column == 7) {
        return stations.getRenderer();
    } else if (column == 8) {
        return new ButtonCellEditor(deleteButton);
    } else {
        return getDefaultRenderer(getModel().getColumnClass(column));
    }
}
项目:jmt    文件:ConnectionsPanel.java   
protected void createRenderers() {
    final TableCellRenderer boolRend = getDefaultRenderer(Boolean.class);
    setDefaultRenderer(Boolean.class, new DisabledCellRenderer() {
        private static final long serialVersionUID = 1L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component cbox = boolRend.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            cbox.setEnabled(true);
            if (value == null) {
                Component disabled = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                cbox.setBackground(disabled.getBackground());
                cbox.setEnabled(false);
            }
            return cbox;
        }
    });
}
项目:jmt    文件:BlockingRegionGroupPanel.java   
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if (column == 1) {
        return grayRenderer;
    } else if (column == 2) {
        return new BooleanCellRenderer();
    } else if (column == 3) {
        return grayRenderer;
    } else if (column == 4) {
        return new BooleanCellRenderer();
    } else if (column == 5) {
        return new ButtonCellEditor(editButton);
    } else if (column == 6) {
        return new DisabledButtonCellRenderer(deleteButton);
    } else {
        return super.getCellRenderer(row, column);
    }
}
项目:incubator-netbeans    文件:CodeSetupPanel.java   
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if (column != 0) {
        return new ParamCellRenderer();
    }
    return super.getCellRenderer(row, column);
}
项目:incubator-netbeans    文件:SwitcherTable.java   
public Component prepareRenderer(
        TableCellRenderer renderer,
        int row,
        int column) {

    SwitcherTableItem item
            = (SwitcherTableItem) getSwitcherTableModel().getValueAt(row, column);

    boolean selected = row == getSelectedRow() &&
            column == getSelectedColumn() && item != null;

    DefaultTableCellRenderer ren = (DefaultTableCellRenderer)
    renderer.getTableCellRendererComponent(this, item,
            selected, selected, row, column);

    if (item == null) {
        // it's a filler space, we're done
        ren.setOpaque(false);
        ren.setIcon(null);
        return ren;
    }

    Icon icon = item.getIcon();
    if (icon == null ) {
        icon = nullIcon;
    }
    ren.setText(selected || item.isActive() ? stripHtml( item.getHtmlName() ) : item.getHtmlName());
    ren.setIcon(icon);
    ren.setBorder(rendererBorder);
    ren.setIconTextGap(42 - icon.getIconWidth());

    if (item.isActive()) {
        // don't use deriveFont() - see #49973 for details
        ren.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize()));
    }

    ren.setOpaque(true);

    return ren;
}
项目:OpenJSharp    文件:XTable.java   
/**
 * This method sets read write rows to be blue, and other rows to be their
 * default rendered colour.
 */
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    DefaultTableCellRenderer tcr =
        (DefaultTableCellRenderer) super.getCellRenderer(row,column);
    tcr.setToolTipText(getToolTip(row,column));
    if (defaultColor == null) {
        defaultColor = tcr.getForeground();
        editableColor = Color.blue;
        errorColor = Color.red;
        // this sometimes happens for some reason
        if (defaultColor == null) {
            return tcr;
        }
    }
    if (column != VALUE_COLUMN) {
        tcr.setForeground(defaultColor);
        return tcr;
    }
    if (isCellError(row,column)) {
        tcr.setForeground(errorColor);
    } else if (isCellEditable(row, column)) {
        tcr.setForeground(editableColor);
    } else {
        tcr.setForeground(defaultColor);
    }
    return tcr;
}
项目:incubator-netbeans    文件:TableSorter.java   
public void setTableHeader(JTableHeader tableHeader) {
    if (this.tableHeader != null) {
        this.tableHeader.removeMouseListener(mouseListener);
        TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
        if (defaultRenderer instanceof SortableHeaderRenderer) {
            this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
        }
    }
    this.tableHeader = tableHeader;
    if (this.tableHeader != null) {
        this.tableHeader.addMouseListener(mouseListener);
        this.tableHeader.setDefaultRenderer(
                new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
    }
}
项目:incubator-netbeans    文件:OutlineView.java   
/** Translate the tree column renderer */
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    TableCellRenderer result = super.getCellRenderer(row, column);
    if (isHScrollingEnabled) {
        int c = convertColumnIndexToModel(column);
        if (c == 0) {
            result = new TranslatedTableCellRenderer(this, result);
        }
    }
    return result;
}
项目:ramus    文件:GroupableTableHeaderUI.java   
/**
 * Calculate and return the height of the header.
 *
 * @return Header Height
 */
@SuppressWarnings("unchecked")
private int getHeaderHeight() {
    int height = 0;
    GroupableTableColumnModel columnModel = (GroupableTableColumnModel) header
            .getColumnModel();
    for (int column = 0; column < columnModel.getColumnCount(); column++) {
        TableColumn aColumn = columnModel.getColumn(column);
        TableCellRenderer renderer = aColumn.getHeaderRenderer();
        if (renderer == null) {
            renderer = header.getDefaultRenderer();
        }
        Component comp = renderer.getTableCellRendererComponent(header
                        .getTable(), aColumn.getHeaderValue(), false, false, -1,
                column);
        int cHeight = comp.getPreferredSize().height;
        Iterator iter = columnModel.getColumnGroups(aColumn);
        if (iter != null) {
            while (iter.hasNext()) {
                ColumnGroup cGroup = (ColumnGroup) iter.next();
                cHeight += cGroup.getSize(header.getTable()).height;
            }
        }
        height = Math.max(height, cHeight);
    }
    return height;
}
项目:incubator-netbeans    文件:SheetTable.java   
/** Returns a reference to the static renderer shared among all instances
 * of SheetTable */
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if( 0 == column ) {
        TableCellRenderer res = getCustomRenderer( row );
        if( null != res )
            return res;
    }
    return getRenderer();
}
项目:OpenJSharp    文件:XMBeanAttributes.java   
@Override
public synchronized Component prepareRenderer(TableCellRenderer renderer,
                                              int row, int column) {
    //In case we have a repaint thread that is in the process of
    //repainting an obsolete table, just ignore the call.
    //It can happen when MBean selection is switched at a very quick rate
    if(row >= getRowCount())
        return null;
    else
        return super.prepareRenderer(renderer, row, column);
}
项目:parabuild-ci    文件:GridSwing.java   
public static void autoSizeTableColumns(JTable table) {

        TableModel  model        = table.getModel();
        TableColumn column       = null;
        Component   comp         = null;
        int         headerWidth  = 0;
        int         maxCellWidth = Integer.MIN_VALUE;
        int         cellWidth    = 0;
        TableCellRenderer headerRenderer =
            table.getTableHeader().getDefaultRenderer();

        for (int i = 0; i < table.getColumnCount(); i++) {
            column = table.getColumnModel().getColumn(i);
            comp = headerRenderer.getTableCellRendererComponent(table,
                    column.getHeaderValue(), false, false, 0, 0);
            headerWidth  = comp.getPreferredSize().width + 10;
            maxCellWidth = Integer.MIN_VALUE;

            for (int j = 0; j < Math.min(model.getRowCount(), 30); j++) {
                TableCellRenderer r = table.getCellRenderer(j, i);

                comp = r.getTableCellRendererComponent(table,
                                                       model.getValueAt(j, i),
                                                       false, false, j, i);
                cellWidth = comp.getPreferredSize().width;

                if (cellWidth >= maxCellWidth) {
                    maxCellWidth = cellWidth;
                }
            }

            column.setPreferredWidth(Math.max(headerWidth, maxCellWidth)
                                     + 10);
        }
    }
项目:parabuild-ci    文件:GridSwing.java   
public static void autoSizeTableColumns(JTable table) {

        TableModel  model        = table.getModel();
        TableColumn column       = null;
        Component   comp         = null;
        int         headerWidth  = 0;
        int         maxCellWidth = Integer.MIN_VALUE;
        int         cellWidth    = 0;
        TableCellRenderer headerRenderer =
            table.getTableHeader().getDefaultRenderer();

        for (int i = 0; i < table.getColumnCount(); i++) {
            column = table.getColumnModel().getColumn(i);
            comp = headerRenderer.getTableCellRendererComponent(table,
                    column.getHeaderValue(), false, false, 0, 0);
            headerWidth  = comp.getPreferredSize().width + 10;
            maxCellWidth = Integer.MIN_VALUE;

            for (int j = 0; j < Math.min(model.getRowCount(), 30); j++) {
                TableCellRenderer r = table.getCellRenderer(j, i);

                comp = r.getTableCellRendererComponent(table,
                                                       model.getValueAt(j, i),
                                                       false, false, j, i);
                cellWidth = comp.getPreferredSize().width;

                if (cellWidth >= maxCellWidth) {
                    maxCellWidth = cellWidth;
                }
            }

            column.setPreferredWidth(Math.max(headerWidth, maxCellWidth)
                                     + 10);
        }
    }
项目:openjdk-jdk10    文件:JTableOperator.java   
/**
 * Maps {@code JTable.getCellRenderer(int, int)} through queue
 */
public TableCellRenderer getCellRenderer(final int i, final int i1) {
    return (runMapping(new MapAction<TableCellRenderer>("getCellRenderer") {
        @Override
        public TableCellRenderer map() {
            return ((JTable) getSource()).getCellRenderer(i, i1);
        }
    }));
}
项目:jmt    文件:JWatVariableInputTable.java   
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if (column == 2) {
        return new ComboBoxCell(VarTypes);
    } else if (column == columnSizes.length - 1) {
        return new ButtonCellEditor(delVar);
    } else {
        return super.getCellRenderer(row, column);
    }
}
项目:JavaGraph    文件:LibrariesTable.java   
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if (convertColumnIndexToModel(column) == Column.URL.ordinal()) {
        return this.urlRenderer;
    } else {
        return super.getCellRenderer(row, column);
    }
}
项目:ramus    文件:ElementAttributesEditor.java   
protected void reload() {
    CloseEvent event = new CloseEvent(this);
    CloseListener[] listeners = getCloseListeners();
    for (CloseListener listener : listeners) {
        listener.closed(event);
        removeCloseListener(listener);
    }

    loadCurrentQualifierAttributes();
    Engine engine = framework.getEngine();
    AccessRules rules = framework.getAccessRules();
    getters = new ValueGetter[attributes.size()];
    renderers = new TableCellRenderer[attributes.size()];
    values = new Object[attributes.size()];
    saveValues = new boolean[attributes.size()];
    Arrays.fill(saveValues, true);
    Arrays.fill(getters, new ValueGetter() {

        @Override
        public Object getValue(TableNode node, int index) {
            return node.getValueAt(index);
        }
    });
    for (int i = 0; i < attributes.size(); i++) {
        Attribute attr = attributes.get(i).attribute;
        AttributePlugin plugin = framework.findAttributePlugin(attr);
        if (plugin instanceof TabledAttributePlugin) {
            ValueGetter getter = ((TabledAttributePlugin) plugin)
                    .getValueGetter(attr, engine, framework, this);
            if (getter != null)
                getters[i] = getter;
        }
        renderers[i] = plugin.getTableCellRenderer(engine, rules, attr);
    }

    loadElement();
}
项目:incubator-netbeans    文件:TableSorter.java   
public void setTableHeader(JTableHeader tableHeader) {
    if (this.tableHeader != null) {
        this.tableHeader.removeMouseListener(mouseListener);
        TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
        if (defaultRenderer instanceof SortableHeaderRenderer) {
            this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
        }
    }
    this.tableHeader = tableHeader;
    if (this.tableHeader != null) {
        this.tableHeader.addMouseListener(mouseListener);
        this.tableHeader.setDefaultRenderer(
                new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
    }
}
项目:incubator-netbeans    文件:PropertiesTable.java   
private void init(JLabel label, String[] columns, TableSorter sorter) {
    tableModel = new PropertiesTableModel(columns);
    tableModel.addTableModelListener(this);
    if(sorter == null) {
        sorter = new TableSorter(tableModel);
    } 
    this.sorter = sorter;   
    table = new SortedTable(this.sorter);
    table.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PropertiesTable.class, "tableProperties.AccessibleContext.accessibleName"));
    table.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PropertiesTable.class, "tableProperties.AccessibleContext.accessibleDescription"));
    table.getTableHeader().setReorderingAllowed(false);
    TableCellRenderer cellRenderer = new PropertiesTableCellRenderer();
    table.setDefaultRenderer(String.class, cellRenderer);
    table.setRowHeight(Math.max(
            table.getRowHeight(),
            cellRenderer.getTableCellRendererComponent(table, "abc", true, true, 0, 0)//NOI18N
                        .getPreferredSize().height + 2));
    //table.setDefaultEditor(CommitOptions.class, new CommitOptionsCellEditor());
    table.getTableHeader().setReorderingAllowed(true);
    table.setRowHeight(table.getRowHeight());
    table.addAncestorListener(this);
    component = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    component.setPreferredSize(new Dimension(340, 150));
    table.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PropertiesTable.class, "ACSD_PropertiesTable")); // NOI18N        
    label.setLabelFor(table);
    setColumns(columns);
}
项目:sstore-soft    文件:GridSwing.java   
public static void autoSizeTableColumns(JTable table) {

        TableModel  model        = table.getModel();
        TableColumn column       = null;
        Component   comp         = null;
        int         headerWidth  = 0;
        int         maxCellWidth = Integer.MIN_VALUE;
        int         cellWidth    = 0;
        TableCellRenderer headerRenderer =
            table.getTableHeader().getDefaultRenderer();

        for (int i = 0; i < table.getColumnCount(); i++) {
            column = table.getColumnModel().getColumn(i);
            comp = headerRenderer.getTableCellRendererComponent(table,
                    column.getHeaderValue(), false, false, 0, 0);
            headerWidth  = comp.getPreferredSize().width + 10;
            maxCellWidth = Integer.MIN_VALUE;

            for (int j = 0; j < Math.min(model.getRowCount(), 30); j++) {
                TableCellRenderer r = table.getCellRenderer(j, i);

                comp = r.getTableCellRendererComponent(table,
                                                       model.getValueAt(j, i),
                                                       false, false, j, i);
                cellWidth = comp.getPreferredSize().width;

                if (cellWidth >= maxCellWidth) {
                    maxCellWidth = cellWidth;
                }
            }

            column.setPreferredWidth(Math.max(headerWidth, maxCellWidth)
                                     + 10);
        }
    }
项目:rapidminer    文件:CollapsibleErrorTable.java   
public CollapsibleErrorTable(AbstractErrorWarningTableModel errorWarningTableModel) {
    this.errorWarningTableModel = errorWarningTableModel;
    errorTable = new JTable(errorWarningTableModel) {

        private static final long serialVersionUID = 1L;

        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            // add tooltip for last column
            JComponent component = (JComponent) super.prepareRenderer(renderer, row, column);
            if (column == getColumnCount() - 1) {
                component.setToolTipText(getValueAt(row, column).toString());
            }
            return component;
        }

    };
    errorScrollPane = new JScrollPane(errorTable);
    errorWarningTableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            update();
        }
    });
    setupGUI();
}
项目:incubator-netbeans    文件:SortedTable.java   
/**
 * Sets a custom sorting renderer, which delegates to the default L&F
 * renderer.
 */
private void setSortingRenderer() {
    if (sorter != null) {       //is null during construction
        TableCellRenderer defaultRenderer = getDefaultRenderer();
        if (!(defaultRenderer instanceof TableSorter.SortableHeaderRenderer)) {
            setDefaultRenderer(sorter.new SortableHeaderRenderer(defaultRenderer));
        }
    }
}