0

I want to make a JTable , where one single cell (not all rows of a column) will contain a JComponent like JdatePicker or JComboBox. I have written this code

    DefaultTableModel dm;
    dm = new DefaultTableModel() {
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return !(columnIndex == 0); //make 0th column non-editable
        }
    };
    Object [] columnHeaders=new Object[]{"Field", "Value"};
    Object [][] data=new Object[][]{{"ID",""},{"Reg Year",""},{"Reg Date", ""}} ;

    regFormTable.setModel(dm); //regFormTable is a Jtable object

I also have a class that implements TableCellrenderer:

public class datePickerCellRenderer extends JFrame implements TableCellRenderer{
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    this.add(new JDateChooser());
    return this;
}

}

How can I use datePickerCellRenderer class to implement as I described. I tried a few ways. None of those worked. [Using Netbeans GUI builder is there a way to do that?]

Plaese ask if any more code I need to add

partho
  • 1,101
  • 2
  • 21
  • 37
  • 2
    You'll need a renderer _and_ an editor; only return a custom component when the row & column parameters match your chosen row & column; please edit your question to include a [mcve] that shows your revised approach.. – trashgod Oct 23 '16 at 11:49
  • 1
    You could take a look at this Stack Overflow question and answers: [How to use custom JTable cell editor and cell renderer](http://stackoverflow.com/questions/11858286/how-to-use-custom-jtable-cell-editor-and-cell-renderer). – Freek de Bruijn Oct 23 '16 at 12:33
  • 1
    most of JDatePickers/Calendars has own code for TableCellEditor/Rendere – mKorbel Oct 24 '16 at 00:05

0 Answers0