0

Well, I'm trying to render some components in the tables mentioned above. I know thats done with implementing a custom TableCellRenderer, and that works just fine in normal JTable, e.g. doing something like this:

import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

public class Test
{
    public static void main(String[] argv)
    {
        String[] columnNames = {"First Name","Last Name","nr"};
        Object[][] data = {{"Homer","Simpson","1"},{"Madge","Simpson","2"},{"Bart","Simpson","3"},
                {"Lisa","Simpson","4"},};


        DefaultTableModel model = new DefaultTableModel(data,columnNames);

        JTable table = new JTable(model);

        table.getColumnModel().getColumn(2).setCellRenderer(new TableCellRenderer(){
            final JButton button = new JButton();
            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
            {
                button.setText(value.toString());
                return button;
            }
    });
        JFrame f = new JFrame();
        f.setSize(300,300);
        f.add(new JScrollPane(table));
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

It also works with JIDE's Sortable- and AggregateTable, but as soon as I replace those tables with Xdev's, the component isn't rendered anymore, so it seems the CellRenderer isn't set properly, even though TableColumn.getCellRenderer() returns the correct class. So does anyone know how to render a component in Xdev's tables? Thanks in advance!

zerdus
  • 1
  • 1
  • Can you maybe try using `setDefaultRenderer()`? I have the feeling the Xdev's table ignores the renderer set per column. So a possible fix could be to set one global renderer for the table and switch beaviour inside this renderer in function of the column. – Eric Leibenguth Jun 22 '15 at 16:23
  • Yep, that works. thanks! – zerdus Jun 23 '15 at 10:05

0 Answers0