I have created a JTable in Netbeans of which the first column consists of checkboxes.
These checkboxes were made by adding
JCheckBox checkBox = new javax.swing.JCheckBox();
and
jTable1.getColumn("ColumnName").setCellEditor(new DefaultCellEditor(checkBox));
under customize code when right-clicking the JTable. And in the Table Contents I specified the datatype to Boolean (I basically followed along the instructions on this website since I had never worked with JTables before: http://ift.tt/1KBD5Qz)
My question now: how do I get the actual checkbox in row=1 & coloumn=1, for example? These attempts aren't working:
JCheckBox j = (JCheckBox) jTable1.getComponent(1);
JCheckBox j = (JCheckBox) jTable1.getModel().getValueAt(1, 1);
I get the error message "java.lang.String cannot be cast to javax.swing.JCheckBox".
For what I'm trying to do, I need to get back the object/component of type "checkbox" and NOT just find out if it is selected or not. Is that possible to do? I'm not super advanced in programming, so that's why I'm having trouble.
Aucun commentaire:
Enregistrer un commentaire