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 :

JCombobox problème de raffraichissement


Sujet :

Composants Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Etudiant en reseaux
    Inscrit en
    Janvier 2013
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Etudiant en reseaux

    Informations forums :
    Inscription : Janvier 2013
    Messages : 35
    Points : 23
    Points
    23
    Par défaut JCombobox problème de raffraichissement
    Bonjour à tous, je suis entrain de coder un mvc en java, sur ma vue je possède un jcombobox, et j'aimerais que lors ce que j'ajoute un client dans mon repertoire ma combobox ce mette à jour.

    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
    package Softphone;
     
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.Observable;
    import java.util.Observer;
     
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
     
     
     
    public class Softphoneview extends JFrame implements Observer {
     
     
    JPanel panel1 ;
     
    // ajout d'un bouton	
    JButton ajout = new JButton ("Ajouter un contact");
    private JPanel pan = new JPanel();
    private JTextField entree = new JTextField(20);
    private JTextField entree1 = new JTextField(20);
    private JTextField entree2 = new JTextField(20);
    private JComboBox contact ;
    private JLabel labelnom = new JLabel("Entrez nom :");
    private JLabel labelprenom = new JLabel("Entrez prenom :");
    private JLabel labelnum = new JLabel("Entrez numero :");
    private Softophone softphone ;
    public Softphoneview(final Softophone softphone, final Softphonecontroler controler)
    {
    	super();
    	this.softphone = softphone ;
    	this.softphone.addObserver(this);
    	this.setTitle("Bouton");
    	this.setSize(700, 550);
    	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	this.setLocationRelativeTo(null);
    	contact = new JComboBox() ;
     
     
    		  for(Contact elem: softphone.repertoire)
    	       {
    	       	String affichage = elem.getfirstName() +" "+  elem.getName() +" "+  elem.getphonenumber() ;
    			  //contact.addItem(affichage);
     
    	       //	System.out.println (elem.getfirstName());
    	       //	System.out.println (elem.getphonenumber());
    	       }
     
     
     
     
     
     
    	pan.setLayout(new FlowLayout());
    	pan.add(ajout);
    	pan.add(labelnom);
    	pan.add(entree);
    	pan.add(labelprenom);
    	pan.add(entree1);
    	pan.add(labelnum);
    	pan.add(entree2);
    	pan.add(contact);
    	this.setContentPane(pan);
    	//this.setVisible(true);
    			ajout.addActionListener(new ActionListener(){
    				public void actionPerformed(ActionEvent event){
    					//Via cette instruction, on passe au prochain conteneur de la pile
    					String value1 = entree.getText();
    					String value2 = entree1.getText();
    					String value3 = entree2.getText();
    					controler.ajoutdecontact(softphone,value1,value2,value3);
          }
        });
     
     
    paint();
    }
     
     
     
    	public void paint() {
    	// TODO Auto-generated method stub
     
    		  for(Contact elem: softphone.repertoire)
    	       {
    	       	String affichage = elem.getfirstName() +" "+  elem.getName() +" "+  elem.getphonenumber() ;
    			  contact.addItem(affichage);
     
    	       //	System.out.println (elem.getfirstName());
    	       //	System.out.println (elem.getphonenumber());
    	       }
    		labelnom.setVisible(true);
    		labelprenom.setVisible(true);
    		labelnum.setVisible(true);
    		entree.setVisible(true);
    		entree2.setVisible(true);
    		entree1.setVisible(true);
    		contact.setVisible(true);
    		pan.setVisible(true);
    		this.setVisible(true);
     
     
    }
     
     
     
    	@Override
    	public void update(Observable o, Object arg) {
    		// TODO Auto-generated method stub
    		repaint();
    		System.out.println ("paint");
    	}
     
     
     
    }
    En sachant que lorsque j'ajoute un client, je passe bien dans le repaint
    Si quelqu'un a une piste ou autres

  2. #2
    Membre à l'essai
    Homme Profil pro
    Etudiant en reseaux
    Inscrit en
    Janvier 2013
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Etudiant en reseaux

    Informations forums :
    Inscription : Janvier 2013
    Messages : 35
    Points : 23
    Points
    23
    Par défaut
    J'ai finalement pu resoudre mon probleme

    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
    package Softphone;
     
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.Observable;
    import java.util.Observer;
     
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
     
     
     
    public class Softphoneview extends JFrame implements Observer {
     
     
    JPanel panel1 ;
     
    // ajout d'un bouton	
    private JButton ajout = new JButton ("Ajouter un contact");
    private JButton rep = new JButton ("repertoire");
    private JButton mess = new JButton ("Ecrire un message");
    private JButton envoyer = new JButton ("Ecrire un message");
    private JPanel pan = new JPanel();
    private JPanel pan2 = new JPanel();
    private JTextField entree = new JTextField(20);
    private JTextField entree1 = new JTextField(20);
    private JTextField entree2 = new JTextField(20);
    private JTextField text = new JTextField(500);
    private JComboBox contact ;
    private JLabel labelnom = new JLabel("Entrez nom :");
    private JLabel labelprenom = new JLabel("Entrez prenom :");
    private JLabel labelnum = new JLabel("Entrez numero :");
    private Softophone softphone ;
    public Softphoneview(final Softophone softphone, final Softphonecontroler controler)
    {
    	super();
    	this.softphone = softphone ;
    	this.softphone.addObserver(this);
    	this.setTitle("Bouton");
    	this.setSize(700, 550);
    	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	this.setLocationRelativeTo(null);
    	contact = new JComboBox() ;
     
     
    		  for(Contact elem: softphone.repertoire)
    	       {
    	       	String affichage = elem.getfirstName() +" "+  elem.getName() +" "+  elem.getphonenumber() ;
    			  contact.addItem(affichage);
     
    	       //	System.out.println (elem.getfirstName());
    	       //	System.out.println (elem.getphonenumber());
    	       }
     
     
     
     
     
     
    	pan.setLayout(new FlowLayout());
    	pan.add(rep);
    	pan.add(mess);
    	pan.add(ajout);
    	pan.add(labelnom);
    	pan.add(entree);
    	pan.add(labelprenom);
    	pan.add(entree1);
    	pan.add(labelnum);
    	pan.add(entree2);
    	pan.add(contact);
    	pan.add(text);
    	pan.add(envoyer);
    	this.setContentPane(pan);
    	//this.setVisible(true);
    			ajout.addActionListener(new ActionListener(){
    				public void actionPerformed(ActionEvent event){
    					//Via cette instruction, on passe au prochain conteneur de la pile
    					String value1 = entree.getText();
    					String value2 = entree1.getText();
    					String value3 = entree2.getText();
    					controler.ajoutdecontact(softphone,value1,value2,value3);
          }
        });
     
    			rep.addActionListener(new ActionListener(){
    				public void actionPerformed(ActionEvent event){
    					//Via cette instruction, on passe au prochain conteneur de la pile
     
    					controler.contact(softphone);
          }
        });
     
    			mess.addActionListener(new ActionListener(){
    				public void actionPerformed(ActionEvent event){
    					//Via cette instruction, on passe au prochain conteneur de la pile
     
    					controler.mess(softphone);
          }
        });
     
    paint(2);
    }
     
     
     
    	public void paint(int a) {
    	// TODO Auto-generated method stub
     
    		if (a == 3)
    		{
    			labelnom.setVisible(false);
    			labelprenom.setVisible(false);
    			labelnum.setVisible(false);
    			entree.setVisible(false);
    			entree2.setVisible(false);
    			entree1.setVisible(false);
    			contact.setVisible(true);
    			ajout.setVisible(false);
    			rep.setVisible(false);
    			mess.setVisible(false);
    			pan.setVisible(true);
    			text.setVisible(true);
    			envoyer.setVisible(true);
     
     
    			this.setVisible(true);
    		}
     
     
    		if (a == 2)
    		{
    			labelnom.setVisible(false);
    			labelprenom.setVisible(false);
    			labelnum.setVisible(false);
    			entree.setVisible(false);
    			entree2.setVisible(false);
    			entree1.setVisible(false);
    			contact.setVisible(true);
    			ajout.setVisible(false);
    			rep.setVisible(true);
    			mess.setVisible(true);
    			pan.setVisible(true);
    			text.setVisible(false);
    			envoyer.setVisible(false);
    			this.setVisible(true);
    		}
     
    		if (a == 0)
    		{
    		rep.setVisible(false);
    		mess.setVisible(false);
    		labelnom.setVisible(true);
    		labelprenom.setVisible(true);
    		labelnum.setVisible(true);
    		entree.setVisible(true);
    		entree2.setVisible(true);
    		entree1.setVisible(true);
    		contact.setVisible(true);
    		text.setVisible(false);
    		envoyer.setVisible(false);
    		pan.setVisible(true);
    		this.setVisible(true);
    		}
     
    		if (a==1)
    		{
     
    		Contact derniercontact = softphone.repertoire.get(softphone.repertoire.size()-1);
    		String affichage = derniercontact.getfirstName() +" "+  derniercontact.getName() +" "+  derniercontact.getphonenumber() ;
    		contact.addItem(affichage);
    		rep.setVisible(false);
    		mess.setVisible(false);
    		labelnom.setVisible(false);
    		labelprenom.setVisible(false);
    		labelnum.setVisible(false);
    		entree.setVisible(false);
    		entree2.setVisible(false);
    		entree1.setVisible(false);
    		contact.setVisible(true);
    		ajout.setVisible(false);
    		text.setVisible(false);
    		envoyer.setVisible(false);
    		pan.setVisible(true);
    		this.setVisible(true);
    		}
     
    }
     
     
     
    	@Override
    	public void update(Observable o, Object arg) {
    		// TODO Auto-generated method stub
    		int a = softphone.getEtat();
    		paint(a);
     
    		System.out.println ("paint");
    	}
     
     
     
    }

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

Discussions similaires

  1. Problème de raffraichissement.
    Par kurul1 dans le forum OpenGL
    Réponses: 6
    Dernier message: 06/02/2006, 16h46
  2. Problème de raffraichissement de listes
    Par blondin01 dans le forum Access
    Réponses: 7
    Dernier message: 13/10/2005, 12h31
  3. [awt] Problème de raffraichissement de composant
    Par FakuFaku dans le forum AWT/Swing
    Réponses: 13
    Dernier message: 21/07/2005, 18h32
  4. [JComboBox] Problème dans le PopMenu après ajout
    Par bidon dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 29/03/2005, 15h52
  5. [swing][JComboBox]Problème de taille
    Par n!co dans le forum Composants
    Réponses: 8
    Dernier message: 06/03/2004, 10h53

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