I used a custom cell render for JTable that contains a JTextfield and JCombobox but the problem that I can't click on them like the are disabled!
this is my code:
public class OvertimeAndProjectRender extends JPanel implements TableCellRenderer{
/**
*
*/
private static final long serialVersionUID = 2079139315339181747L;
Project p = new Project();
private List<Project> listProject;
JComboBox<ComboItem> projectComboBox = new JComboBox<ComboItem>();
public OvertimeAndProjectRender(int idChef) {
listProject = p.getListProjectsForSelectedChef(idChef);
fillCombobox();
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) {
this.setLayout(new BorderLayout(0, 0));
JTextField t = new JTextField();
this.add(t, BorderLayout.NORTH);
this.add(projectComboBox, BorderLayout.SOUTH);
return this;
}
private void fillCombobox() {
int nbIde = listProject.size();
for(int i=0; i<nbIde; i++){
String key = Integer.toString(listProject.get(i).getId());
String value = listProject.get(i).getDesignation();
projectComboBox.addItem(new ComboItem(key, value));
}
}
}
And this how I called the custom cellRender:
tablePointage.getColumnModel().getColumn(2).setCellRenderer(new OvertimeAndProjectRender(idChef));
And this is the picture of JTable:
(source: hostingpics.net)