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

AWT/Swing Java Discussion :

actualisation d'une combobox


Sujet :

AWT/Swing Java

  1. #1
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 36
    Points : 17
    Points
    17
    Par défaut actualisation d'une combobox
    Bonjour a tous,voila, j'ai une combobox qui liste des mode_de_paiement :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    public JComboBox getJComboBox_paiment_famclients() {
    		if (jComboBox_paiment_famclients == null) {
    			jComboBox_paiment_famclients = new JComboBox();
    			jComboBox_paiment_famclients.setBounds(new Rectangle(162, 184, 120, 24));
     
     
    		}
    		return jComboBox_paiment_famclients;
    avec un bouton a coté qui ouvre une popup contenant une combobox, et 1 bouton qui permet d'ajouter un mode_de_paiement :

    combo :

    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
    private JComboBox getJComboBox_mdp_client() {
    		if (jComboBox_mdp_client == null) {
    			jComboBox_mdp_client = new JComboBox();
    			jComboBox_mdp_client.setBounds(new Rectangle(14, 80, 123, 23));
     
    			jComboBox_mdp_client.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
    					String valeur =(String) jComboBox_mdp_client.getSelectedItem();
     
    					jTextField_designation_paiement_famclients.setText(valeur);
    					{
    						Statement instruction = null;
    						Connection connexion = null;
    						ResultSet resultat = null;
    						try
    						{
    							Class.forName("com.mysql.jdbc.Driver");
     
    							connexion = DriverManager.getConnection("jdbc:mysql://localhost/gescom2","root","");
    							instruction = connexion.createStatement();
     
    							resultat = instruction.executeQuery("SELECT code_mdp FROM mode_de_paiement WHERE lib_mdp = '"+valeur+"'" );
    							resultat.next();
     
     
    							{
    								jTextField_code_paiement_famclients.setText((resultat.getString("code_mdp")));
    							}
     
     
     
     
     
     
     
    						}
    						catch (ClassNotFoundException ex)
    						{
    							JOptionPane.showMessageDialog(null,"Classe introuvable" + ex.getMessage());
    						}
    						catch (SQLException ex)
    						{
    							JOptionPane.showMessageDialog(null, "Connexion impossible:" +ex.getMessage());
    						}
    						finally
    						{
    							try
    							{
     
    								if(connexion !=null)
    									connexion.close();
    								if(instruction !=null)
    									instruction.close();
    								if (connexion !=null)
    									connexion.close();
    							}
    							catch (SQLException ex)
    							{
    								ex.printStackTrace();
    							}
    						}
    				}
    				}
    			});
    			jComboBox_mdp_client.getSelectedItem();
     
     
    		}
    		return jComboBox_mdp_client;
    bouton ajouter :

    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
    private JButton getJButton_ajouter_famclients() {
    		if (jButton_ajouter_famclients == null) {
    			jButton_ajouter_famclients = new JButton();
    			jButton_ajouter_famclients.setBounds(new Rectangle(148, 80, 92, 24));
    			jButton_ajouter_famclients.setText("Ajouter");
    			jButton_ajouter_famclients.addActionListener(new java.awt.event.ActionListener() {
    			public void actionPerformed(java.awt.event.ActionEvent e){
    			{
    				Statement instruction = null;
    				Connection connexion = null;
    				ResultSet resultat = null;
     
    				try
    				{
    					Class.forName("com.mysql.jdbc.Driver");
     
    					connexion = DriverManager.getConnection("jdbc:mysql://localhost/gescom2","root","");
    					instruction = connexion.createStatement();
    					resultat = instruction.executeQuery("SELECT lib_mdp FROM mode_de_paiement" );
     
     
     
     
     
    						instruction.executeUpdate("INSERT INTO mode_de_paiement(lib_mdp) VALUES('"+jTextField_designation_paiement_famclients.getText()+"')");
    						resultat = instruction.executeQuery("SELECT lib_mdp FROM mode_de_paiement" );
    						jFrame_paiement_famclients.setVisible(false);
    						paiement_famclients pai= new paiement_famclients();
    						pai.getJFrame_paiement_famclients();
    				}
    				catch (ClassNotFoundException ex)
    				{
    					JOptionPane.showMessageDialog(null,"Classe introuvable" + ex.getMessage());
    				}
    				catch (SQLException ex)
    				{
    					JOptionPane.showMessageDialog(null, "Connexion impossible:" + ex.getMessage());
    				}
    				finally
    				{
    					try
    					{
     
    						if(connexion !=null)
    							connexion.close();
    						if(instruction !=null)
    							instruction.close();
    						if (connexion !=null)
    							connexion.close();
    					}
    					catch (SQLException ex)
    					{
    						ex.printStackTrace();
    					}
    				}
    		}
    			}
    			});
    		}
     
     
    		return jButton_ajouter_famclients;
    	}
    qui en meme temps reactualise mon popup et donc ma combo quand je clique dessus.

    mes 2 combos sont remplies de la meme maniere ( elles doivent donc contenir la meme chose) :
    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
    {
    			Statement instruction = null;
    			Connection connexion = null;
    			ResultSet resultat = null;
    			try
    			{
    				Class.forName("com.mysql.jdbc.Driver");
     
    				connexion = DriverManager.getConnection("jdbc:mysql://localhost/gescom2","root","");
    				instruction = connexion.createStatement();
     
    				resultat = instruction.executeQuery("SELECT lib_mdp FROM mode_de_paiement" );
     
     
    				while(resultat.next())
    				{
    					jComboBox_mdp_client.addItem((resultat.getString("lib_mdp")));
    				}
     
     
     
     
     
     
     
    			}
    			catch (ClassNotFoundException ex)
    			{
    				JOptionPane.showMessageDialog(null,"Classe introuvable" + ex.getMessage());
    			}
    			catch (SQLException ex)
    			{
    				JOptionPane.showMessageDialog(null, "Connexion impossible:" +ex.getMessage());
    			}
    			finally
    			{
    				try
    				{
     
    					if(connexion !=null)
    						connexion.close();
    					if(instruction !=null)
    						instruction.close();
    					if (connexion !=null)
    						connexion.close();
    				}
    				catch (SQLException ex)
    				{
    					ex.printStackTrace();
    				}
    			}
    	}
     
    		return jPanel_paiement_famclients;
    	}
    le Probleme est que quand j'ajoute un paiement dans la combo de mon popup l'actualisation se passe bien mais , quand je ferme mon popup la combo de ma page principal est restée telle qu'elle etait alors que la base de données a bien changée, j'ai deja essayer uptadeUI mais rien a faire, auriez vous une idée pour actualiser quand je clique sur mon bouton ajouter svp??

  2. #2
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 36
    Points : 17
    Points
    17
    Par défaut
    quelqu'un aurait-il meme juste une indication ou une page à aller voir? ou meme une autre méthode? peut-être ai-je mal cherché

  3. #3
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 36
    Points : 17
    Points
    17
    Par défaut
    un pti up, si quelqu'un a une reponse svp.. ( même pour m'envoyer...)

  4. #4
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 36
    Points : 17
    Points
    17
    Par défaut
    quelqu'un a-t-il une réponse svp?

  5. #5
    Membre habitué Avatar de titus55
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 115
    Points : 136
    Points
    136
    Par défaut
    Salut,
    utilise plutôt un modèle que tu appliques à ta combobox pour l'actualiser (cf la javadoc).

  6. #6
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mai 2007
    Messages
    36
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2007
    Messages : 36
    Points : 17
    Points
    17
    Par défaut
    merci je vais essayer ca

Discussions similaires

  1. Multi-selection dans une ComboBox ?
    Par Moloko dans le forum MFC
    Réponses: 5
    Dernier message: 07/07/2021, 17h26
  2. [Débutant] C# actualiser une comboBox
    Par Tanaes dans le forum C#
    Réponses: 6
    Dernier message: 31/01/2015, 10h12
  3. Probleme d'actualisation d'une combobox
    Par PascalStl dans le forum Général Python
    Réponses: 8
    Dernier message: 30/01/2014, 05h35
  4. probleme actualisation d'une combobox générée par macro.
    Par elombre dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 11/06/2009, 12h38
  5. Code d'actualisation d'une combobox
    Par benoit13 dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 01/07/2008, 16h30

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