I am trying to add jRadioButton into jTable. I used the given code
private class CustomCellRenderer extends DefaultTableCellRenderer {
/* (non-Javadoc)
* @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
*/
@Override
public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) {
return new javax.swing.JRadioButton();
}
}
But when I run this I am getting jTable column in a different color and when I click on radio Button nothing happens. I am using netbeans. If I try to Customize the jTable then nothing will appear in jTable. Give me a proper guidance.
TableCellEditor.JRadioButtonin your renderer and reuse it everywhere, that is the purpose of TableCellRenderer.super.getTableCellRendererComponent, it is not need to extendDefaultTableCellRenderer, simply implementTableCellRenderer.Consider reading the JTable tutorial to understand better the concepts of renderers and editors.
EDIT:
Here is an example on how you can make this work. Of course, you’ll have to adapt to your model but you should get the gist: