Adding jRadioButton into jTable

前端 未结 2 1932
遥遥无期
遥遥无期 2020-11-27 08:27

I am trying to add jRadioButton into jTable. I used the given code

 private class CustomCellRenderer extends DefaultTableCellRende         


        
2条回答
  •  被撕碎了的回忆
    2020-11-27 08:53

    1. It is not recommended to return a new component in the getTableCellRendererComponent method. Instead, always return the same component, but modify it according to the value. This is possible since the returned component is merely used as a 'stamp' and not added directly to the Swing hierarchy. See the Renderers and Editors section in the tutorial
    2. What I described in the first point explains why you cannot click on the button. It is merely an image of the button that is present in the table, not a real button

    Also, consider using a JCheckbox instead of a radiobutton. In that case you can simply stick to the default renderer / editor when your TableModel contains boolean values

提交回复
热议问题