JCombobox et JCheckBox dans un JTable
thierryProg
Messages postés
10
Date d'inscription
Statut
Membre
Dernière intervention
-
thierryProg Messages postés 10 Date d'inscription Statut Membre Dernière intervention -
thierryProg Messages postés 10 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
voila je veut mettre un JCombobox et JCheckBox dans mon Jtable pour mettre à jour les données en sélectionnant la ligne mais quand je le fais ça affiche un /*(javax.swing.JComboBox[,0,0,0x0,layout=javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager,alignmentX=0.0,alignmentY=0.0,border=,flags=328,maximumSize=,minimumSize=,preferredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=En attente])*/ dans mon JTable et je ne voie pas ou mettre instanciation de ma classe pour que ça marche
Voic ma classe pour le JComboBox et JChekBox dans ma VueJComboJCheck.java:
Mon code pour afficher le tableau :
Merci pour vos futurs réponses
voila je veut mettre un JCombobox et JCheckBox dans mon Jtable pour mettre à jour les données en sélectionnant la ligne mais quand je le fais ça affiche un /*(javax.swing.JComboBox[,0,0,0x0,layout=javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager,alignmentX=0.0,alignmentY=0.0,border=,flags=328,maximumSize=,minimumSize=,preferredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=En attente])*/ dans mon JTable et je ne voie pas ou mettre instanciation de ma classe pour que ça marche
Voic ma classe pour le JComboBox et JChekBox dans ma VueJComboJCheck.java:
public class VueJComboJCheck extends DefaultTableCellRenderer
{
private static final long serialVersionUID = 1L;
@SuppressWarnings("rawtypes")
public Component getComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column)
{
if(value instanceof JComboBox) //si la valeur est un JComboBox
{
return (JComboBox) value;
}
if(value instanceof Boolean) //si la valeur esr boolean
{
JCheckBox cb = new JCheckBox();
cb.setSelected(((Boolean) value).booleanValue());
return cb;
}
if(value instanceof JCheckBox) //si la valeur est un JCheckbox
{
return (JCheckBox) value;
}
return new JTextField(value.toString());
}
}
Mon code pour afficher le tableau :
public class VueMiseAJourReservation extends JPanel implements ActionListener
{
private JLabel lbTitre = new JLabel("Mettre à jour statut les Reservations");
private String[] choixStatut = {"En attente", "Éffectué"};
private JComboBox statut = new JComboBox(this.choixStatut);
private JCheckBox selectionLigne = new JCheckBox();
private JTable tableMJReservations;
private JButton Maj = new JButton("Mise à Jour");
public VueMiseAJourReservation()
{
this.setBounds(50, 10, 450, 260); //fenetre reservation (margin-left,margin top, longueur, largeur)
this.setLayout(null); //pas de photo
this.setBackground(new Color(102, 153, 204)); //couleur bleu marine
this.lbTitre.setBounds(160, -10, 200, 50); //placement titre
this.add(this.lbTitre); //ajout titre
String entete [] = {"id de la Reservation", " date et heure", "nombre de personne",
"statut", "sélection"};
this.tableMJReservations = new JTable(this.extraireReservations(), entete); //creation tableaux
this.tableMJReservations.getColumnModel().getColumn(0).setCellRenderer(new VueJComboJCheck()); //appelle de ma classe
JScrollPane uneScroll = new JScrollPane(tableMJReservations);
uneScroll.setBounds(25, 30, 400, 180);
this.add(uneScroll);
this.setVisible(false);
}
private Object[][] extraireReservations() {
ArrayList<Reservation> lesReservations = ModeleReservation.selectAll();
Object [][]donnees = new Object[lesReservations.size()][5];
int i = 0;
for(Reservation uneReservation : lesReservations)
{
donnees [i][0] = uneReservation.getIdReservation();
donnees [i][1] = uneReservation.getDateHeureReservation();
donnees [i][2] = uneReservation.getNbPersonnes();
donnees [i][3] = this.add(this.statut);
donnees [i][4] = this.add(this.selectionLigne);
i++;
}
return donnees;
}
Merci pour vos futurs réponses
javax.swing.JComboBox[,0,0,0x0,layout=javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager,alignmentX=0.0,alignmentY=0.0,border=,flags=328,maximumSize=,minimumSize=,preferredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=En attente]
Le résultat que tu voulais étant certainement "En attente" tu devrais utiliser la méthode JComboBox.getSelectedItem() pour avoir cette valeur.
Dans le cas d'un JCheckBox, ce serait la méthode isSelected().