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

 Java Discussion :

Problème avec refresh d'elements


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Juillet 2005
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 35
    Par défaut Problème avec refresh d'elements
    Salut à tous,

    Je suis en train de faire un logiciel pour mon bahut
    et j'ai un problèmeuhhh que me soule depuis maintenant pas loin de 4h...

    Alors j'ai une JComboBox qui s'affiche et qui doit à la sélection d'un element de la liste, charger des données d'une base pour ensuite activer une autre combo box (enabled) et lui inserer les données...

    Bon le chargement de la base ca marche nikel, rien à dire... Mais quand il s'agit de l'afficher... ca ne marche pas, sauf si je refait un setPanelXXXX() < une méthode que j'ai codé ... Vous avez déjà eu ce problème ?

    Bon maintenant j'en suis (avec très très peu de méthode) à faire des gros repaint() de tout mais ca ne marche pas plus ...

    Si vous voulez mon 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
    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
    public void setPanelCreerFiche(){
                    // Suppression de tout ce qu'il y avait avant
    		this.getPanelPrincipal().removeAll();
                    // Affichage
    		GridBagConstraints gbc = new GridBagConstraints();
    		// [...]
    		gbc.gridx = 0;
    		gbc.gridwidth = 1;
    		gbc.gridy++;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		this.getPanelPrincipal().add(new JLabel("Adresse :"),gbc);
     
    		gbc.gridx = 1;
    		gbc.anchor = GridBagConstraints.CENTER;
                   // C'est ce combo box qui doit agir sur l'autre 
    	this.getPanelPrincipal().add(this.getCreationFicheComboVille(),gbc);
    		//[....]
            this.getPanelPrincipal().add(this.getCreationFicheComboRue(),gbc);
    	        // [...]
    	}
    // CA MARCHE IMPEC'
    public JComboBox getCreationFicheComboVille(){
    		if(this.creationFicheComboVille == null){
    			String[][] tabCPVille = Adresse.getAllCPVille();
    			String[] entreesTableau = new String[((tabCPVille[0].length)+2)];
    			entreesTableau[0] = " ";
    			for(int i = 1; i < tabCPVille[0].length+1; i++){
    				entreesTableau[i] = tabCPVille[0][i-1]+" - "+tabCPVille[1][i-1];
    			}
    			entreesTableau[entreesTableau.length-1] = "Autre ...";
    			DefaultComboBoxModel model = new DefaultComboBoxModel(entreesTableau);
    			this.creationFicheComboVille = new JComboBox(model);
    			this.creationFicheComboVille.addActionListener(this);
    		}
    		return this.creationFicheComboVille;
    	}
     
    	public JComboBox getCreationFicheComboRue(){
    		if(this.creationFicheComboRue == null){
    			String[] entreesTableau = new String[1];
    			entreesTableau[0] = " ";
    			DefaultComboBoxModel model = new DefaultComboBoxModel(entreesTableau);
    			this.creationFicheComboRue = new JComboBox(model);
    			this.creationFicheComboRue.addActionListener(this);
    		}
    		return this.creationFicheComboRue;
    	}
     
    	public void setCreationFicheComboRue(String[] tabCPVille){
    		if(this.creationFicheComboRue == null){
    			this.getCreationFicheComboRue();
    		}
    		String[] tabRue = Adresse.getRueByCPVille(tabCPVille);
    		DefaultComboBoxModel model = null;
    		if(tabRue != null){
    			String[] entreesTableau = new String[tabRue.length+2];
    			entreesTableau[0] = " ";
    			for(int i = 1; i < tabRue.length+1; i++){
    				entreesTableau[i] = tabRue[i-1];
    			}
    			entreesTableau[entreesTableau.length-1] = "Autre ...";
    			model = new DefaultComboBoxModel(entreesTableau);
    			this.creationFicheComboRue = new JComboBox(model);
    		}else{
    			this.creationFicheComboRue = null;
    			this.getCreationFicheComboRue();
    		}
    	}
     
    public void actionPerformed(ActionEvent e){
    		Object element = e.getSource();
                    //[...]
                     if(element == creationFicheComboVille){
    			if(creationFicheComboVille.getSelectedItem() == "Autre ..."){
    				this.getCreationFicheChampAutreCP().setEditable(true);
    				this.getCreationFicheChampAutreCP().setText("");
    				this.getCreationFicheChampAutreVille().setEditable(true);
    				this.getCreationFicheChampAutreVille().setText("");
    				for(int i = 0; i < getPanelPrincipal().getComponentCount(); i++){
    					getPanelPrincipal().getComponent(i).repaint();
    				}
    			}else if(creationFicheComboVille.getSelectedItem() == " "){
    				this.getCreationFicheChampAutreCP().setEditable(false);
    				this.getCreationFicheChampAutreCP().setText("CP");
    				this.getCreationFicheChampAutreVille().setEditable(false);
    				this.getCreationFicheChampAutreVille().setText("Nom de la Ville");
    				this.setCreationFicheComboRue(null);
    				this.getCreationFicheComboNumero(null).setEnabled(false);
    				for(int i = 0; i < getPanelPrincipal().getComponentCount(); i++){
    					getPanelPrincipal().getComponent(i).repaint();
    				}
    			}else{
    				this.getCreationFicheChampAutreCP().setEditable(false);
    				this.getCreationFicheChampAutreCP().setText("CP");
    				this.getCreationFicheChampAutreVille().setEditable(false);
    				this.getCreationFicheChampAutreVille().setText("Nom de la Ville");
    				String elementSel = (String)creationFicheComboVille.getSelectedItem();
    				String[] decomposition = elementSel.split(" - ");
    				if(decomposition.length > 2){
    					for(int i = 2; i < decomposition.length; i++){
    						decomposition[1] = decomposition[1].concat(" - "+decomposition[i]);
    					}
    				}
    				this.setCreationFicheComboRue(decomposition);
    				for(int i = 0; i < getPanelPrincipal().getComponentCount(); i++){
    					getPanelPrincipal().getComponent(i).repaint();
    				}
    			}
    		}//[...]
    }

  2. #2
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Fais un appel à la méthode revalidate() du JPanel auquel tu ajoutes ton (tes) composant(s) après l'ajout.

  3. #3
    Membre averti
    Inscrit en
    Juillet 2005
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 35
    Par défaut
    Merci pour ta réponse :

    Bon y'a un truc qui claque : c'est que ca résout un de mes problèmes ...
    Mais pas celui la .....

    Je suis toujours obligé de rappeler le "set" pour faire apparaitre les bonnes valeurs dans la Combo box

  4. #4
    Membre averti
    Inscrit en
    Juillet 2005
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 35
    Par défaut
    Est-ce qu'au moins c'est possible ??? Oui je pense...
    Mais ce qui est bizarre c'est quand je fais un System.out.println des elements de ma liste... c'est les bons elements qui sont noté à chaque fois mais ... ca ne s'actualise pas sur cet sal****ie de Panel

    Si vous voulez un autre bout de code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    else if(element == menuItemAjouterFiche){
    			this.setPanelCreerFiche();
    		}
    Ca c'est dans le listener : et "menuItemAjouterFiche" c'est un menu item...
    Mais voila rien de spécial

  5. #5
    Membre averti
    Inscrit en
    Juillet 2005
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 35
    Par défaut
    Bon ben les gars ....

    Je viens d'y penser, apparament il faut qu'il soit remove et réajouté donc ce que j'ai fait c'est un l'utilsation de ma méthode set =)

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

Discussions similaires

  1. problème avec positionnement des elements en ASP.NET
    Par af.zakaria dans le forum ASP.NET
    Réponses: 2
    Dernier message: 12/04/2012, 08h41
  2. Réponses: 6
    Dernier message: 18/12/2007, 10h42
  3. [DOM4J] Problème avec org.dom4j.Element
    Par Dx_ter dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 23/10/2007, 18h09
  4. Réponses: 1
    Dernier message: 24/08/2007, 09h29
  5. Réponses: 1
    Dernier message: 08/08/2006, 15h39

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