mercredi 25 novembre 2020

How to change the icon of the checkbox in the Jtable?

I've generated a column consist of checkboxes using the Boolean.class shown on my code, my problem is that I don't know how to change the icon of the checkboxes. Can you show some examples how this can be done?

 public class MyTableModel extends DefaultTableModel{

public MyTableModel() {
  super(new String[]{"Question No.", "Question", "Satisfied", "Not Satisfied"}, 0);
}

@Override
public Class<?> getColumnClass(int columnIndex) {
  Class cls = String.class;
  switch (columnIndex) {
     case 0:
      cls = Integer.class;
      break;
      case 1:
      cls = Integer.class;
      break;
     case 2:
      clazz = Boolean.class;
      break;
      case 3:
      cls = Boolean.class;
      break;
  }
  return clazz;
}

@Override
public boolean isCellEditable(int row, int column) {
  switch (column) {
     case 0: return false;
     case 1: return false;
     case 2: return ! ((Boolean) getValueAt(row, 3)).booleanValue();
     case 3:
        return ! ((Boolean) getValueAt(row, 2)).booleanValue();
 }
return true;
}



Aucun commentaire:

Enregistrer un commentaire