In java Swing table, how to split a cell into two, one is TextField, another one is a checkbox. I have done some codes, but doesn’t work. thanks
public class CustomTableCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object obj, boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = super.getTableCellRendererComponent(table, obj, isSelected, hasFocus, row, column);
JTextField fld = new JTextField();
JCheckBox chx = new JCheckBox();
cell.add(fld); // Doesn't work
cell.add(chx); // Doesn't work
return cell;
}
}
1) in this case you have to define for
LayoutManager, becauseJLabel/JComponent(by default returnTableCellRenderer) doesn’t implemented any LayoutManager2) put
JPanelnested another JComponents (JPanelhas by defaultFlowLayout) into Cell3) most confortable will be put
JTextFieldto one Column andBooleanvalue (returnsJCheckBox) to another Column