Bouton suivant et précédent sur Jtable

Fermé
isa.dama Messages postés 28 Date d'inscription mardi 15 mai 2018 Statut Membre Dernière intervention 16 mars 2023 - 16 nov. 2020 à 12:43
Bonjour,
J'ai un soucis que j'essaie de résoudre depuis maintenant 2 semaines.

J'ai une fiche de salarié a laquelle j'ai ajouté des boutons "suivant , précédent , premier et dernier".

Les actions de ces boutons sont liés à ma table "Salarié" qui s'affiche dans un tableau à gauche de ma fenêtre.
Ce tableau dois afficher uniquement trois champs de ma table employe de la BD (matricule, nom et prénom) en passant sur une requête SQL.
Pourtant, le bouton "suivant" par exemple dépend de ce tableau de trois colonne.

en cliquant sur une ligne du tableau, j'ai environ 34 champs qui sont actualisés sur l'écran.

Ce que je cherche à faire, c'est qu'en cliquant sur les "suivant , précédent , premier et dernier" que ces 34 champs soient actualisés car actuellement seul les 3 champs correspondant au contenu de mon tableau Jtable1 sont actualisés.
Les autres champs ne changent pas.
Comment les actualiser en cliquant sur les les 4 boutons?

Merci d'avance!!

Je vous joint le code et une capture de ma fiche employé actuel.





 private void getData(){
try{

java.sql.Statement stmt1=maConnexion.ObtenirConnexion().createStatement();
java.sql.ResultSet resultat= stmt1.executeQuery("SELECT matricule, nom, prenom, nomMarital FROM EMPLOYE");
jTable1.setModel(DbUtils.resultSetToTableModel(resultat));




}catch(SQLException e){

}
}





int d;
void defilement (int defil) throws ParseException{

try{

if (d==0){
jBpremier.setEnabled(false);
jBprecedent.setEnabled(false);
} else{

jBpremier.setEnabled(true);
jBprecedent.setEnabled(true);
}

if(d==jTable1.getRowCount()-1){

jBdernier.setEnabled(false);
jBsuivant.setEnabled(false);
} else{

jBdernier.setEnabled(true);
jBsuivant.setEnabled(true);

}





jTMatricule.setText(jTable1.getValueAt(defil, 0).toString());
jTNom.setText(jTable1.getValueAt(defil, 1).toString());
jTPrenom.setText(jTable1.getValueAt(defil, 2).toString());
jTMarital.setText(jTable1.getValueAt(defil, 3).toString());
jTComp1.setText(jTable1.getValueAt(defil, 4).toString());
jTComp2.setText(jTable1.getValueAt(defil, 5).toString());
jTComp3.setText(jTable1.getValueAt(defil, 6).toString());
jTPComent.setText(jTable1.getValueAt(defil, 7).toString());
jTVarLibre1.setText(jTable1.getValueAt(defil, 8).toString());
jTVarLibre2.setText(jTable1.getValueAt(defil, 9).toString());
jTVarLibre3.setText(jTable1.getValueAt(defil, 10).toString());
jTVarLibre4.setText(jTable1.getValueAt(defil, 12).toString());
jTVarLibre5.setText(jTable1.getValueAt(defil, 13).toString());
jTVarLibre6.setText(jTable1.getValueAt(defil, 14).toString());
jCSexe.setSelectedItem(jTable1.getValueAt(defil, 15).toString());
jCTitre.setSelectedItem(jTable1.getValueAt(defil, 16).toString());
jCPaysNationalite.setSelectedItem(jTable1.getValueAt(defil, 17).toString());
jCPaysNationalite.setSelectedItem(jTable1.getValueAt(defil, 18).toString());
jCcrit1.setSelectedItem(jTable1.getValueAt(defil, 19).toString());
jCcrit2.setSelectedItem(jTable1.getValueAt(defil, 20).toString());
jCcrit3.setSelectedItem(jTable1.getValueAt(defil, 21).toString());
jCcrit4.setSelectedItem(jTable1.getValueAt(defil, 22).toString());
jCcrit5.setSelectedItem(jTable1.getValueAt(defil, 23).toString());
jCcrit6.setSelectedItem(jTable1.getValueAt(defil, 124).toString());
jCcrit7.setSelectedItem(jTable1.getValueAt(defil, 25).toString());
jCcrit8.setSelectedItem(jTable1.getValueAt(defil, 26).toString());
jCcrit9.setSelectedItem(jTable1.getValueAt(defil, 27).toString());
jCcrit10.setSelectedItem(jTable1.getValueAt(defil, 28).toString());
jCcrit11.setSelectedItem(jTable1.getValueAt(defil, 29).toString());
jCcrit12.setSelectedItem(jTable1.getValueAt(defil, 30).toString());
jCMode.setSelectedItem(jTable1.getValueAt(defil, 31).toString());

String dat=jTable1.getValueAt(defil, 32).toString();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date= df.parse(dat);
jTDateNais.setDate(date);
jTDateMois.setDate(date);




}
catch(Exception e){
//JOptionPane.showMessageDialog(null,e);
}
}

//premier
void premier(){
try {

d=0;
defilement(d);

}
catch(Exception e){
//JOptionPane.showMessageDialog(null,e);
}
}

//précédent

void precedent(){
try {

d--;
defilement(d);

}
catch(Exception e){
//JOptionPane.showMessageDialog(null,e);
}
}

//suivant

void suivant(){
try {

d++;
defilement(d);

}
catch(Exception e){
//JOptionPane.showMessageDialog(null,e);
}
}


//dernier

void dernier(){
try {

d=jTable1.getRowCount()-1;
defilement(d);

}
catch(Exception e){
//JOptionPane.showMessageDialog(null,e);
}
}

Configuration: Windows / Edge 86.0.622.68