1 pièce(s) jointe(s)
Boolean et du texte dans une cellules d'une JTable
Bonjour,
est-il possible de reproduire la photo ci-dessous dans une JTable ?
Pièce jointe 204323
J'ai pensé à mettre un JCheckBox comme Renderer:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public class CellRenderer extends JCheckBox implements TableCellRenderer {
public CellRenderer() {
super();
setHorizontalAlignment(JCheckBox.CENTER);
setBorderPainted(true);
setOpaque(true);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Color alternate = UIManager.getColor("Table.alternateRowColor");
Color normal = new Color(table.getBackground().getRGB());
if(isSelected) {
setForeground(table.getSelectionForeground());
setBackground(table.getSelectionBackground());
//setText("OK");
} else {
setForeground(table.getForeground());
setBackground(alternate != null && row % 2 == 0 ? alternate : normal);
//setText("Non");
}
setEnabled(table.isCellEditable(row, column));
setSelected(value != null && (Boolean)value);
return this;
}
} |
Le hic, c'est que je bloque au niveau du modèle. Comment attribut deux valeurs différentes pour une cellule ?
En fait, j'ai comme l'impression que je dois envoyer mon objet "Choix" dans mon rendu, mais là aussi je bloque ?
Quelqu'un aurait-il une idée ?
Merci