Java 8 TableCellRenderer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TableCellRenderer class.

This code example shows how to use the following methods:getTableCellRendererComponent
        model.setValueAt('2', 0, 1);
 
        JTable table = new JTable(model);
        TableCellRenderer renderer = new SudokuCellRenderer();
 
        JLabel cell1 = (JLabel) renderer.getTableCellRendererComponent(table, '1', false, false, 0, 0);
        assert cell1.getText().equals("1") : "Wrong text at cell 1: " + cell1.getText();
        assert cell1.getFont().isBold() : "Fixed cells should be rendered in bold.";
        JLabel cell2 = (JLabel) renderer.getTableCellRendererComponent(table, '2', false, false, 0, 1);
        assert cell2.getText().equals("2") : "Wrong text at cell 2: " + cell2.getText();
        assert cell2.getFont().isBold() : "Fixed cells should be rendered in bold.";
        // Check an empty cell, it should have no text. 
        JLabel cell3 = (JLabel) renderer.getTableCellRendererComponent(table, null, false, false, 0, 2);
        assert cell3.getText().length() == 0 : "Wrong text at cell 3: " + cell3.getText();
    } 
 
 
    @BeforeClass 
    public void createTable() 
    { 
6
CodeRank
This code example shows how to use the following methods:getTableCellRendererComponent
This code example shows how to use the following methods:getTableCellRendererComponent
        if(isSelected || hasFocus) return c;
 
        final JStockOptions jStockOptions = MainFrame.getInstance().getJStockOptions();
 
        c.setForeground(jStockOptions.getNormalTextForegroundColor());
 
        c.setBackground(getBackgroundColor(row));
 
        return c;
    } 
} 
3
CodeRank
This code example shows how to use the following methods:getTableCellRendererComponent
            DistinctColumnItem item = (DistinctColumnItem) value;
            TableCellRenderer renderer = table.getCellRenderer( item.getRow(), column);
             
            try { 
                 
                Component cmpt = renderer.getTableCellRendererComponent(
                        table, item.getValue(), isSelected, hasFocus(), item.getRow(), column );
 
                Method method = cmpt.getClass().getMethod("getText");
                Object s = method.invoke(cmpt);
                 
                if ( s instanceof String ) {
                    setText( (String)s );
                } 
                 
            } catch (Throwable e) {
//                e.printStackTrace(); 
            } 
             
        } 
3
CodeRank
This code example shows how to use the following methods:getTableCellRendererComponent
     * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) 
     */ 
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean isEnabled, int row, int col) {
        if ((value != null) && (value instanceof Date)) value = format.format((Date) value); 
        Component retorno = renderer.getTableCellRendererComponent(table, value, isSelected, isEnabled, row, col);
        return retorno;
    } 
 
} 
3
CodeRank
This code example shows how to use the following methods:getTableCellRendererComponent
            this.alignment = alignment;
        } 
 
        @Override public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component cellRendererComp =
                    delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 
            if (cellRendererComp instanceof DefaultTableCellRenderer) {
                ((DefaultTableCellRenderer) cellRendererComp).setHorizontalAlignment(alignment);
            } 
 
            return cellRendererComp;
        } 
    } 
 
    ///////////////////////////////////////////// TableColumnModelListener ///////////////////////////////////////////// 
 
    @Override public void columnAdded(TableColumnModelEvent e) {
        installInOneColumn(table, e.getToIndex(), alignment);  // Only install in added column.
4
CodeRank
This code example shows how to use the following methods:getTableCellRendererComponent
This code example shows how to use the following methods:getTableCellRendererComponent
This code example shows how to use the following methods:getTableCellRendererComponent
        this.tableCellRenderer = tableCellRenderer;
    } 
 
    @Override 
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component c = tableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 
        if (c instanceof JLabel) {
            JLabel l = (JLabel) c;
 
            l.setHorizontalTextPosition(SwingConstants.LEADING);
 
            int index;
            index = ((SortableTableModel) table.getModel()).getSortedColumn();
            index = table.convertColumnIndexToView(index);
 
            if (index == column) {
                if (((SortableTableModel) table.getModel()).getAscending()) {
                    l.setIcon(UIManager.getLookAndFeelDefaults().getIcon("Table.ascendingSortIcon"));
                } else { 
4
CodeRank
This code example shows how to use the following methods:getTableCellRendererComponent
        final TableCellRenderer delegate = header.getDefaultRenderer();
        final TableCellRenderer newRenderer = new TableCellRenderer() {
 
            @Override 
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                final Component component = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                // to display the table header in disabled state when the table is disabled. 
                component.setEnabled(table.isEnabled());
                return component;
            } 
        }; 
        header.setDefaultRenderer(newRenderer);
        setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    } 
 
    @Override 
    public ListWrappingTableModel getModel() { 
        return (ListWrappingTableModel) super.getModel(); 
    } 
 
4
CodeRank
See Code Examples for Java 8 TableCellRenderer Methods: