IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants Java Discussion :

Récuperer un élément sélectionné dans un JTable sur combobox


Sujet :

Composants Java

  1. #1
    Futur Membre du Club Avatar de ComorienKM
    Homme Profil pro
    Amateur
    Inscrit en
    Août 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Comores

    Informations professionnelles :
    Activité : Amateur

    Informations forums :
    Inscription : Août 2017
    Messages : 13
    Points : 8
    Points
    8
    Par défaut Récuperer un élément sélectionné dans un JTable sur combobox
    Bonjour à tous et à toutes!

    J’espère que tout le monde va bien par ici, voilà je suis nouveau ici et amateur de la programmation. Actuellement je suis sur un projet de gestion de personnel avec Java et Mysql. J'ai un problème depuis environs 3 jours. Je n'arrive pas à récupérer la donnée sélectionnée sur ma Jtable pour l'afficher dans un combobox. Par contre sur les textfield ça marche bien mais avec le combo ça ne marche pas.

    Voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    private void deplace(int i) {
            try {
                txtid.setText(model.getValueAt(i, 0).toString());
                txtnm.setText(model.getValueAt(i, 1).toString());
                txtpr.setText(model.getValueAt(i, 2).toString());
                txtda.setText(model.getValueAt(i, 3).toString());
                txtad.setText(model.getValueAt(i, 4).toString());
                txttel.setText(model.getValueAt(i, 5).toString());
                txtstat.setSelectedItem(model.getValueAt(i, 6).toString());
                txtfnct.setSelectedItem(model.getValueAt(i, 7).toString());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Erreur de deplacement" + e.getLocalizedMessage());
            }
     
        }
     
     
        private void afficher() {
            try {
                stmt = con.obtenirconnection().createStatement();
                rs = stmt.executeQuery("SELECT * from profil,fonction,statut where fonction.idFonction=profil.idFonction and statut.idStatut=profil.idStatut");
                while (rs.next()) {
                    model.addRow(new Object[]{rs.getString("identifiant"), rs.getString("nom"), rs.getString("prenom"), rs.getString("sexe"),
                        rs.getString("adresse"), rs.getString("tel"), rs.getString("nomFonction"), rs.getString("nomStatut")});
                }
                table.setModel(model);
            } catch (SQLException e) {
                System.err.println(e);
            }
     
        }

  2. #2
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Les combos en question (je suppose que c'est txtstat et txtfnct ?), elles manipulent bien des données de type String ? La valeur sélectionnée existe-elle bien dans le modèle de la combo ?
    Comment les déclares-tu ?

    Il y a une chose un peu bizarre qui pourrait être une piste : à priori, je dirais que txtstat c'est pour le statut et txtfnct pour la fonction. Or ces données ont pour index (dans le modèle de la JTable) 6 pour la fonction et 7 pour le statut. Et l'affectation est dans l'autre sens. Je m'attendrais en toute logique à :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    txtfnct.setSelectedItem(model.getValueAt(i, 6).toString());
    txtstat.setSelectedItem(model.getValueAt(i, 7).toString());
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  3. #3
    Futur Membre du Club Avatar de ComorienKM
    Homme Profil pro
    Amateur
    Inscrit en
    Août 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Comores

    Informations professionnelles :
    Activité : Amateur

    Informations forums :
    Inscription : Août 2017
    Messages : 13
    Points : 8
    Points
    8
    Par défaut
    Les combos en question (je suppose que c'est txtstat et txtfnct ?), elles manipulent bien des données de type String ? La valeur sélectionnée existe-elle bien dans le modèle de la combo ?
    Comment les déclares-tu ?
    Oui C bien ça! Elle manipule des donnés de types String(Deja enregistré sur la BDD)!! Une fois lancée, les comboBox affichent les differentes fonction existantes dans la base de donéé(grace a SELECT ).Le probleme C'est quan je selectionne sur Jtable ,les combo n'affichent pas les donnés selectionnés.
    y a une chose un peu bizarre qui pourrait être une piste : à priori, je dirais que txtstat c'est pour le statut et txtfnct pour la fonction. Or ces données ont pour index (dans le modèle de la JTable) 6 pour la fonction et 7 pour le statut
    Merci de me l'avoire rappeller! mais une fois changer ça marche toujours pas!!!
    ++Mrci

  4. #4
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Tu ne me montres pas comment tu déclares ces JComboBox !

    Comme suit ou autrement ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    JComboBox<String> txtfnct = new JCombBox<>();
    Au niveau des valeurs, dans la combo, je suppose que tu affiches des libellés. Mais dans la jtable, sont-ce bien des libellés pour le statut et la fonction, ou sont-ce des identifiants ?

    A la limite, me montrer tout le code me permettrait d'y voir plus clair, d'avoir une vue d'ensemble, de pointer du doigt le problème, plutôt que d'énumérer les milliers de raisons pour lesquelles ça pourrait ne pas fonctionner.

    Une autre voie à explorer est celle de la multi-instance (l'instance de combo visible dans l'interface et l'instance modifiée lors de la sélection ne sont pas les mêmes).
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  5. #5
    Futur Membre du Club Avatar de ComorienKM
    Homme Profil pro
    Amateur
    Inscrit en
    Août 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Comores

    Informations professionnelles :
    Activité : Amateur

    Informations forums :
    Inscription : Août 2017
    Messages : 13
    Points : 8
    Points
    8
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    JComboBox<String> txtfnct = new JCombBox<>();
    je n'ai pas declarer les combo, je les ai juste attribuer les nom txtfnct et txtstat

    Au niveau des valeurs, dans la combo, je suppose que tu affiches des libellés. Mais dans la jtable, sont-ce bien des libellés pour le statut et la fonction, ou sont-ce des identifiants ?
    Au niveau des combo j'affiche des bien des libellés se trouvant sur une de mes tables SQL,et oui dans la Jtable ce sont des libellés pour statut et fonction.

    A la limite, me montrer tout le code me permettrait d'y voir plus clair, d'avoir une vue d'ensemble, de pointer du doigt le problème, plutôt que d'énumérer les milliers de raisons pour lesquelles ça pourrait ne pas fonctionner.

    Une autre voie à explorer est celle de la multi-instance (l'instance de combo visible dans l'interface et l'instance modifiée lors de la sélection ne sont pas les mêmes).
    Voici le code pour recuperer sur combo(txtstat),pour chaque combo g utilse une fonction specifique....!!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     private void comboS() {
            //RECUPERATION SUR COMBO
            try {
                String sql = "SELECT  nomStatut FROM statut";
     
                rs = stmt.executeQuery(sql);
     
                while (rs.next()) {
                    //String fonction = rs.getString("nomFonction");
                    String statut = rs.getString("nomStatut");
                    txtstat.addItem(statut);
                    //txtfnct.addItem(fonction);
                }
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, e);
            }
     
        }
    Voici le code pour le deplacement sur Jtable(selection des libellés)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
       private void tableMouseClicked(java.awt.event.MouseEvent evt) {                                   
            try {
                int i = table.getSelectedRow();
     
                deplace(i);
     
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Erreur de Deplacement" + e.getLocalizedMessage());
            }
        }

  6. #6
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Citation Envoyé par ComorienKM Voir le message
    je n'ai pas declarer les combo, je les ai juste attribuer les nom txtfnct et txtstat
    Tu les as forcément déclarées : il est impossible d'utiliser des variables non déclarées car il est impossible d'utiliser des variables non typées et que le type est donné à la déclaration.
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  7. #7
    Futur Membre du Club Avatar de ComorienKM
    Homme Profil pro
    Amateur
    Inscrit en
    Août 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Comores

    Informations professionnelles :
    Activité : Amateur

    Informations forums :
    Inscription : Août 2017
    Messages : 13
    Points : 8
    Points
    8
    Par défaut
    Voici le code tout en entier!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
     
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.swing.JOptionPane;
    import javax.swing.table.DefaultTableModel;
     
    public class NewJFrame extends javax.swing.JFrame {
     
        Connecter con = new Connecter();
        Statement stmt;
        ResultSet rs;
        DefaultTableModel model = new DefaultTableModel();
     
        public NewJFrame() {
            initComponents();
     
            model.addColumn("Matricule");
            model.addColumn("Nom");
            model.addColumn("Prenom");
            model.addColumn("Sexe");
            model.addColumn("Adresse");
            model.addColumn("Tel");
            model.addColumn("Statut");
            model.addColumn("Fonction");
     
            afficher();
            //table.setModel(model);
            //comboS();
            //comboF();
     
            /* try {
                rs = stmt.executeQuery("SELECT COUNT (*) FROM profil  ");
              int total ;          
               rs.next();
               total=rs.getInt(1)+1;
               
     
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Erreur d'affichage" + e.getLocalizedMessage());
            }*/
        }
     
        private void afficher() {
            try {
                stmt = con.obtenirconnection().createStatement();
                rs = stmt.executeQuery("SELECT * from profil,fonction,statut where fonction.idFonction=profil.idFonction and statut.idStatut=profil.idStatut");
                while (rs.next()) {
                    model.addRow(new Object[]{rs.getString("identifiant"), rs.getString("nom"), rs.getString("prenom"), rs.getString("sexe"),
                        rs.getString("adresse"), rs.getString("tel"), rs.getString("nomFonction"), rs.getString("nomStatut")});
                }
                table.setModel(model);
            } catch (SQLException e) {
                System.err.println(e);
            }
     
        }
     
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            jPanel1 = new javax.swing.JPanel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            jLabel6 = new javax.swing.JLabel();
            txtpr = new javax.swing.JTextField();
            txtnm = new javax.swing.JTextField();
            txtfnct = new javax.swing.JComboBox<>();
            txtstat = new javax.swing.JComboBox<>();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            txtrec = new javax.swing.JTextField();
            jLabel7 = new javax.swing.JLabel();
            txtmdp = new javax.swing.JPasswordField();
            jScrollPane1 = new javax.swing.JScrollPane();
            table = new javax.swing.JTable();
            jLabel8 = new javax.swing.JLabel();
            jLabel9 = new javax.swing.JLabel();
            txtda = new javax.swing.JTextField();
            txttel = new javax.swing.JTextField();
            jLabel10 = new javax.swing.JLabel();
            txtad = new javax.swing.JTextField();
            jButton4 = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            txtid = new javax.swing.JLabel();
            jButton5 = new javax.swing.JButton();
            jLabel11 = new javax.swing.JLabel();
            txteff = new javax.swing.JLabel();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel2.setText("ID");
     
            jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel3.setText("Nom");
     
            jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel4.setText("Prenom");
     
            jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel5.setText("Statut");
     
            jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel6.setText("Fonction");
     
            txtpr.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    txtprActionPerformed(evt);
                }
            });
     
            txtnm.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    txtnmActionPerformed(evt);
                }
            });
     
            txtstat.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    txtstatActionPerformed(evt);
                }
            });
     
            jButton1.setText("Enregistrer");
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
                }
            });
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            jButton2.setText("Modifier");
     
            jButton3.setText("Supprimer");
            jButton3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton3ActionPerformed(evt);
                }
            });
     
            jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel7.setText("Password");
     
            table.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null, null, null, null, null},
                    {"", null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null, null}
                },
                new String [] {
                    "Matricule", "Nom", "Prenom", "Sexe", "Addresse", "Tel", "Statut", "Fonction"
                }
            ));
            table.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    tableMouseClicked(evt);
                }
            });
            jScrollPane1.setViewportView(table);
     
            jLabel8.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel8.setText("Sexe");
     
            jLabel9.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel9.setText("Telephone");
     
            txtda.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    txtdaActionPerformed(evt);
                }
            });
     
            txttel.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    txttelActionPerformed(evt);
                }
            });
     
            jLabel10.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
            jLabel10.setText("Addresse");
     
            txtad.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    txtadActionPerformed(evt);
                }
            });
     
            jButton4.setText("Recherche");
            jButton4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton4ActionPerformed(evt);
                }
            });
     
            jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 36)); // NOI18N
            jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            jLabel1.setText("LISTE DU PERSONNEL ");
            jLabel1.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
     
            jButton5.setText("Actualiser");
            jButton5.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton5ActionPerformed(evt);
                }
            });
     
            jLabel11.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel11.setText("Effectif :");
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(29, 29, 29)
                                        .addComponent(txtad, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(txtstat, 0, 203, Short.MAX_VALUE)
                                                .addComponent(txtfnct, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                        .addGap(1, 1, 1))))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(29, 29, 29)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtpr, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                                    .addComponent(txtnm)
                                    .addComponent(txtda)
                                    .addComponent(txtid, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txttel, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                                .addComponent(txtmdp))))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 633, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel11)
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 459, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(txteff, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(txtrec, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGap(15, 15, 15))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(10, 10, 10)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtnm, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(7, 7, 7))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(26, 26, 26)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtrec, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(1, 1, 1)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txteff, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtpr, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtda, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtad, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txttel, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtmdp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtstat, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(42, 42, 42)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(txtfnct, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(50, 50, 50)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(88, 88, 88))
            );
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 382, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
            );
     
            pack();
        }// </editor-fold>                        
    private void deplace(int i) {
     
            try {
                txtid.setText(model.getValueAt(i, 0).toString());
                txtnm.setText(model.getValueAt(i, 1).toString());
                txtpr.setText(model.getValueAt(i, 2).toString());
                txtda.setText(model.getValueAt(i, 3).toString());
                txtad.setText(model.getValueAt(i, 4).toString());
                txttel.setText(model.getValueAt(i, 5).toString());
                txtfnct.setSelectedItem(model.getValueAt(i, 6));
                txtstat.setSelectedItem(model.getValueAt(i, 7).toString());
     
     
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Erreur de deplacement" + e.getLocalizedMessage());
                System.err.println(e);
            }
     
        }
     
        private void comboS() {
            //RECUPERATION SUR COMBO Statu
            try {
                String sql = "SELECT  nomStatut FROM statut";
     
                rs = stmt.executeQuery(sql);
     
                while (rs.next()) {
                    //String fonction = rs.getString("nomFonction");
                    String statut = rs.getString("nomStatut");
                    txtstat.addItem(statut);
                    //txtfnct.addItem(fonction);
                }
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, e);
            }
     
        }
     
        private void comboF() {
            // RECUPERATION SUR COMBO Fonction
            try {
                String sql = "SELECT  nomFonction FROM fonction";
     
                rs = stmt.executeQuery(sql);
     
                while (rs.next()) {
                    String fonction = rs.getString("nomFonction");
                    //String statut = rs.getString("nomStatut");
                    //txtstat.addItem(statut);
                    txtfnct.addItem(fonction);
                }
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, e);
            }
     
        }
        private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            try {
                /// RECHERCER PAR NOM
                String rech = txtrec.getText();
                model.setRowCount(0);
                rs = stmt.executeQuery("SELECT * from profil,fonction,statut where fonction.idFonction=profil.idFonction and statut.idStatut=profil.idStatut AND NOM='" + rech + "' ");
                while (rs.next()) {
                    Object[] profil = {rs.getString("identifiant"), rs.getString("nom"), rs.getString("prenom"), rs.getString("sexe"),
                        rs.getString("adresse"), rs.getString("tel"), rs.getString("nomFonction"), rs.getString("nomStatut")};
                    model.addRow(profil);
                }
                if (model.getRowCount() == 0) {
                    JOptionPane.showMessageDialog(null, "Aucun Agent");
                } else {
                    int i = 0;
                    deplace(i);
                }
            } catch (Exception e) {
                System.err.println();
                JOptionPane.showMessageDialog(null, e.getMessage());
            }
        }                                        
        private void clear() {
            //FORMATAGE DES ZONE DE SAISIES
            try {
                txtid.setText("");
                txtnm.setText("");
                txtpr.setText("");
                txtda.setText("");
                txtad.setText("");
                txttel.setText("");
                txtmdp.setText("");
                txtstat.setSelectedItem("");
                txtfnct.setSelectedItem("");
            } catch (Exception e) {
                System.err.println();
            }
        }
        private void txtadActionPerformed(java.awt.event.ActionEvent evt) {                                      
            // TODO add your handling code here:
        }                                     
     
        private void txttelActionPerformed(java.awt.event.ActionEvent evt) {                                       
            // TODO add your handling code here:
        }                                      
     
        private void txtdaActionPerformed(java.awt.event.ActionEvent evt) {                                      
            // TODO add your handling code here:
        }                                     
     
        private void tableMouseClicked(java.awt.event.MouseEvent evt) {                                   
            try {
                int i = table.getSelectedRow();
     
                deplace(i);
     
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Erreur de Deplacement" + e.getLocalizedMessage());
            }
        }                                  
     
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            try {
                // SUPPRESSION
                String id = txtid.getText();
                if (JOptionPane.showConfirmDialog(null, "Attention vous voulez supprimer un agent", "Supprimer Agent", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
                    if (id.length() != 0) {
                        stmt.executeUpdate("DELETE FROM profil WHERE identifiant='" + id + "' ");
     
                    } else {
                        JOptionPane.showMessageDialog(null, "Veuillez selectionner un agent");
                    }
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Erreur de Suppression" + e.getLocalizedMessage());
            }
     
        }                                        
     
        private void txtstatActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
        }                                       
     
        private void txtnmActionPerformed(java.awt.event.ActionEvent evt) {                                      
            // TODO add your handling code here:
        }                                     
     
        private void txtprActionPerformed(java.awt.event.ActionEvent evt) {                                      
            // TODO add your handling code here:
        }                                     
     
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
     
        }                                     
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // ENREGISTREMMENT
            String nom = txtnm.getText();
            String prnm = txtpr.getText();
            String sexe = txtda.getText();
            String adr = txtad.getText();
            String tel = txttel.getText();
            String mdp = txtmdp.getText();
            Object stat = txtstat.getSelectedItem();
            Object fonc = txtfnct.getSelectedItem();
     
            String req1 = "INSERT INTO profil (idFonction,idStatut) select idFonction,idStatut from fonction,statut Where nomFonction='" + fonc + "' And nomStatut='" + stat + "' ";
            // String req = "INSERT INTO PROFIL(nom,prenom,sexe,adresse,tel,password) VALUES ('" + nom + "','" + prnm + "','" + sexe + "','" + adr + "','" + tel + "','" + mdp + "')";
     
            try {
                stmt.executeUpdate(req1);
                //stmt.executeUpdate(req);
     
                JOptionPane.showMessageDialog(null, "Insertion Reussie");
     
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, "Erreur d'enregistrement\n" + e.getLocalizedMessage());
     
            }
        }                                        
     
        private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
            // ACTUALISER
            try {
                model.setRowCount(0);
                stmt = con.obtenirconnection().createStatement();
                rs = stmt.executeQuery("SELECT * from profil,fonction,statut where fonction.idFonction=profil.idFonction and statut.idStatut=profil.idStatut");
                while (rs.next()) {
                    model.addRow(new Object[]{rs.getString("identifiant"), rs.getString("nom"), rs.getString("prenom"), rs.getString("sexe"),
                        rs.getString("adresse"), rs.getString("tel"), rs.getString("nomFonction"), rs.getString("nomStatut")});
                }
     
            } catch (SQLException e) {
                System.err.println(e);
            }
     
            clear();
     
        }                                        
     
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JButton jButton4;
        private javax.swing.JButton jButton5;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable table;
        private javax.swing.JTextField txtad;
        private javax.swing.JTextField txtda;
        private javax.swing.JLabel txteff;
        private javax.swing.JComboBox<String> txtfnct;
        private javax.swing.JLabel txtid;
        private javax.swing.JPasswordField txtmdp;
        private javax.swing.JTextField txtnm;
        private javax.swing.JTextField txtpr;
        private javax.swing.JTextField txtrec;
        private javax.swing.JComboBox<String> txtstat;
        private javax.swing.JTextField txttel;
        // End of variables declaration                   
    }

  8. #8
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Ok.

    Donc on voit bien :
    1. La déclaration des variables, en tant que variables de classe (attributs) :
      Code : Sélectionner tout - Visualiser dans une fenêtre à part
      1
      2
      3
       
      private javax.swing.JComboBox<String> txtfnct;
      private javax.swing.JComboBox<String> txtstat;
    2. L'initialisation, dans initComponents() :
      Code : Sélectionner tout - Visualiser dans une fenêtre à part
      1
      2
       txtfnct = new javax.swing.JComboBox<>();
      txtstat = new javax.swing.JComboBox<>();
    3. L'ajout et layout dans l'UI, pour qu'on les voit dans initComponents() également, et ce sont bien les mêmes instances qui sont affichées et que dans lesquelles tu sélectionnes tes valeurs.
    4. Le remplissage avec des valeurs, respectivement, txtstat dans comboS(), et txtfnct dans comboF() :
      Code : Sélectionner tout - Visualiser dans une fenêtre à part
      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
      36
      37
      private void comboS() {
             //RECUPERATION SUR COMBO Statu
             try {
                 String sql = "SELECT  nomStatut FROM statut";
       
                 rs = stmt.executeQuery(sql);
       
                 while (rs.next()) {
                     //String fonction = rs.getString("nomFonction");
                     String statut = rs.getString("nomStatut");
                     txtstat.addItem(statut);
                     //txtfnct.addItem(fonction);
                 }
             } catch (SQLException e) {
                 JOptionPane.showMessageDialog(null, e);
             }
       
         }
       
         private void comboF() {
             // RECUPERATION SUR COMBO Fonction
             try {
                 String sql = "SELECT  nomFonction FROM fonction";
       
                 rs = stmt.executeQuery(sql);
       
                 while (rs.next()) {
                     String fonction = rs.getString("nomFonction");
                     //String statut = rs.getString("nomStatut");
                     //txtstat.addItem(statut);
                     txtfnct.addItem(fonction);
                 }
             } catch (SQLException e) {
                 JOptionPane.showMessageDialog(null, e);
             }
       
         }
      Au passage, tu ne libères par les ressources du ResultSet, ce qu'il faut toujours faire pour éviter de consommer de la mémoire inutilement. Pour ces cas, à priori, c'est appelé une fois pour un faible nombre de valeur, donc ce n'est pas très grave, mais il vaut mieux prendre l'habitude de le faire systématiquement (et fe faire aussi pour les connexions).
      Code : Sélectionner tout - Visualiser dans une fenêtre à part
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      private void comboS() {
             //RECUPERATION SUR COMBO Statu
                 String sql = "SELECT  nomStatut FROM statut";
       
                 try(ResultSet rs = stmt.executeQuery(sql)) {
       
                 while (rs.next()) {
                     String statut = rs.getString("nomStatut");
                     txtstat.addItem(statut);
                 }
             } catch (SQLException e) {
                 JOptionPane.showMessageDialog(null, e);
             }
       
         }
      Il vaudrait mieux utiliser par ailleurs un PreparedStatement, pour éviter les possibilités injection (glisser dans l'appel un code SQL indésirable, qui permettrait d'utiliser ta connexion pour voler ou détruire des données).
      En revanche, aucune des deux méthodes ne sont appelées. Le code sensé le faire est commenté :
      Code : Sélectionner tout - Visualiser dans une fenêtre à part
      1
      2
      //comboS();
      //comboF();
      Donc les combos n'ont aucune valeur dans la liste déroulante et elles sont de type "non éditable". Donc tu ne peux pas sélectionner de valeur dedans.
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  9. #9
    Futur Membre du Club Avatar de ComorienKM
    Homme Profil pro
    Amateur
    Inscrit en
    Août 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Comores

    Informations professionnelles :
    Activité : Amateur

    Informations forums :
    Inscription : Août 2017
    Messages : 13
    Points : 8
    Points
    8
    Par défaut Resolution
    Merci Beaucoup!! Aprés .ça marche, j'avais oublier de appeler les fonction pour afficher les combo en les mettant en commentaire! mais G enlever les commentaires!

  10. #10
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Je pense que tu ne m'as pas compris :

    1. on ne peut sélectionner de valeur qui n'existe pas dans la liste de valeurs si la combo est non éditable
    2. comme tes combos sont vides, tu ne peux donc sélectionner aucune valeur
    3. si tu rends ta combo éditable, on peut saisir n'importe quoi, donc possiblement des valeurs qui n'existent pas dans ta liste de valeurs possibles
    4. il faut que ta combo soit non éditable, mais qu'elle contienne juste les valeurs possibles, afin que lorsque tu sélectionnes un élément, la valeur de la propriété correspondante puisse y être sélectionnée
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 20/05/2017, 01h21
  2. Réponses: 2
    Dernier message: 06/06/2008, 21h32
  3. [Débutant] copier l'élément sélectionner dans une liste
    Par Henry9 dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 29/04/2007, 22h49
  4. Récupérer l'élément sélectionné dans un GtkTree
    Par slasher-fun dans le forum GTK+ avec C & C++
    Réponses: 1
    Dernier message: 07/03/2007, 18h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo