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

Interfaces Graphiques en Java Discussion :

Mise à jour d'une liste à partir d'une sélection dans une autre liste


Sujet :

Interfaces Graphiques en Java

  1. #1
    Nouveau membre du Club
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Points : 25
    Points
    25
    Par défaut Mise à jour d'une liste à partir d'une sélection dans une autre liste
    Bonjour,

    Je construis actuellement une interface graphique dans laquelle on retrouve trois listes .La première est chargée à partir d'un fichier se trouvant sur le serveur (pas de pb), la seconde est mise à jour par une sélection d'une ligne dans la première liste( pas de pb), la troisième est actualisée par un choix effectué dans la deuxième liste.
    C'est sur dernière liste que je rencontre un souci, elle n'est pas mise à jour à chaque sélection dans la deuxième liste.Pourtant l'évènement semble fonctionner correctement car si je teste par un affichage il fonctionne à chaque fois, le problème semble venir de l'alimentation de la liste
    Si quelqu'un pouvait me fournir une explication rationnelle .


    Voici le code pour la gestion des events des listes :
    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
     
       public void valueChanged(ListSelectionEvent evt)
       {
       if (evt.getSource() == LResuUniv )
         {
    	 if ( evt.getValueIsAdjusting())
    	     {
    		 ChoixResuuniv=(String)LResuUniv.getSelectedValue() ;
    	 //System.out.println((String)LResuUniv.getSelectedValue() ) ;
    	     }
    	 }
       else if (evt.getSource() == LCombiBase )
          {
          if ( evt.getValueIsAdjusting())
    	  {
    	     System.out.println((String)LCombiBase.getSelectedValue()) ;
    	      Choixlcombibase=(String)LCombiBase.getSelectedValue() ;
    	      Sinstdep=Choixlcombibase.substring(0,6) ;
    		  strip1=Choixlcombibase.split(":") ;
     
    		  Shostdep=strip1[1] ;
    		  Shostarr=strip1[2] ; 
     
    		 cmd2="rsh "+Shostdep+" -l root \"cat /cadnat/save/DS_v6.0.1/log/"+Sinstdep+"/copie_db*|grep \\\"Fin de la procedure Ora_endbackup\\\" |cut -c1-17|tail -10\"" ;
    		 System.out.println(cmd2) ;
             //LResuUniv.removeListSelectionListener(this) ;
    		 //cmd2="rsh 156701a001dbs -l root \"cat /cadnat/save/DS_v6.0.1/log/oo2p80/copie_db*|grep \\\"Fin de la procedure Ora_endbackup\\\" |cut -c1-17|tail -10\"";
    		 Enveloppe.clear();
    		 LResuUniv.clearSelection () ;
    		 Alim_Resu_Univ(cmd2) ;
    		 //LResuUniv.addListSelectionListener(this) ; 
    	  } 		 
     
    	  } 
       }
    est voici le code pour le chargement de la troisième liste au moyen de la méthode suivante :
    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
     
    public void Alim_Resu_Univ(String shell)
       {
        try {
     
    String[] cmdi = { "/bin/sh", "-c", shell };
    //String[] cmd = { "/bin/sh", "-c", "ls -rtl /universe_log/CNAM50/exp/log/*PB80PEXJOSV020*|tail -1|cut -d: -f2|cut -c4-" };
    //String cmd="/cadnat/ctige/script/java/test.sh" ;
     
    Runtime runtime2 = Runtime.getRuntime();
    final Process process2 = runtime2.exec(cmdi);
     
    // Consommation de la sortie standard de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader2 = new BufferedReader(new InputStreamReader(process2.getInputStream()));
    			String line = "";
    			try {
    			    //Enveloppe.clear();
    				while((line = reader2.readLine()) != null) {
    					// Traitement du flux de sortie de l'application si besoin est
    					//topTextArea.append(line+"\n") ;
    					Enveloppe.addElement(line.substring(0,17)) ;
    				}
     
    			} finally {
    				reader2.close();
     
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();
     
    // Consommation de la sortie d'erreur de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader3 = new BufferedReader(new InputStreamReader(process2.getErrorStream()));
    			String line = "";
    			try {
    				while((line = reader3.readLine()) != null) {
    					// Traitement du flux d'erreur de l'application si besoin est
    					topTextArea.append("\n"+line+"\n") ;
    				}
    			} finally {
    				reader3.close();
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();	
        }
                     catch(Exception e) 
             { 
                  topTextArea.append(e.getMessage()) ;
                  //topTextArea.append(e.printStackTrace()); 
             }   
       }
    La troisième liste se nomme Enveloppe.

    Merci pour votre réponse

  2. #2
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Points : 7 163
    Points
    7 163
    Par défaut
    D'après ce que j'ai compris, tu remplis le modèle de la troisième liste. Par contre tu n'appelles pas de méthode "fire_*" sur ton modèle.
    Je pense que les données sont correctement insérées dans le modèle mais que l'objet graphique n'est pas averti des changements, il ne fait donc pas de nouvel affichage.
    Mais tu ne donne pas assez de code pour statuer sur ce problème

  3. #3
    Nouveau membre du Club
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Points : 25
    Points
    25
    Par défaut
    Voici le code en entier, mais je n'ai pas bien compris la réponse concernant la methode fire_* ...

    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
     
    import javax.swing.*;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import java.awt.Dimension;
    import java.awt.Color;
    import java.util.Vector ;
    import javax.swing.event.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseListener;
    import java.awt.* ;
    import java.io.*;
    import java.sql.*;
    //import oracle.jdbc.driver.*;
    import java.lang.* ;
    import java.util.ArrayList ;
     
    class Ajout_Dbf extends JPanel implements  ActionListener,ListSelectionListener
    {
        JButton button1,button2 ;
       	JTextArea topTextArea ;
    	Vector listeItems ;
    	JList liste,LResuUniv,LCombiBase ;
        JScrollPane listeAvecAscenseur,LResuUnivAvecAscenceur,LCombiBaseAvecAscenceur;
        Dimension preferredSize, dimlist,DimLResuUniv,DimLCombiBase,preferredSize2 ;
        DefaultListModel Enveloppe,Enveloppe2 ;
     
    	String fichier ="/cadnat/ctige/script/java/choix_resto_base.txt";
     
    	String chaine="";
     
    	String cmd1="";
    	String cmd2="";
    	String cmd3="";
     
    	String Base_dep="";
    	String Base_arr="";
    	String Host_dep="";
    	String Host_arr="";
     
    	String Choixlcombibase="" ;
    	String ChoixResuuniv="" ;
     
    	String[] strip1={"","",""} ;
     
    	String Sinstdep="";
    	String Sinstarr="";
    	String Shostdep="";
    	String Shostarr="" ;
     
    	//tableau de stockage ligne
    	ArrayList TabLectureChoix =new ArrayList() ;
     
     
       public Ajout_Dbf()
       { 
        //Bouton Go
        button1 = new JButton("Go");
     
    	//Bouton Clear
    	button2 = new JButton("Clear");
     
    	//Liste deroulante 
        Vector<String> listeItems = new Vector<String>();
        listeItems.addElement("Chargement Offre") ;
        listeItems.addElement("Date Automatique") ;
        listeItems.addElement("Date Manuelle");
        listeItems.addElement("Aide sur l'outil") ;
    	liste = new JList(listeItems);
        liste.setSelectedIndex(0);
        liste.setVisibleRowCount(1); 
        listeAvecAscenseur = new JScrollPane(liste) ;
        Dimension dimlist = new Dimension(180,55) ;
        listeAvecAscenseur.setPreferredSize(dimlist) ;
    	liste.addListSelectionListener(this) ;
     
    	//Liste des combinaises de base possible
     
       this.Enveloppe2 = new DefaultListModel();
       LCombiBase = new JList(Enveloppe2) ;
       //this.add(Lclasse) ;	
       //Lclasse.addListSelectionListener(this) ;
       LCombiBaseAvecAscenceur = new JScrollPane(LCombiBase) ;
       DimLCombiBase = new Dimension(250,55) ;
       LCombiBaseAvecAscenceur.setPreferredSize(DimLCombiBase) ;
       LCombiBase.addListSelectionListener(this) ;
     
    	//Liste resultat universe
       this.Enveloppe = new DefaultListModel();
       LResuUniv = new JList(Enveloppe) ;
       //this.add(Lclasse) ;	
       //Lclasse.addListSelectionListener(this) ;
       LResuUnivAvecAscenceur = new JScrollPane(LResuUniv) ;
       DimLResuUniv = new Dimension(180,100) ;
       LResuUnivAvecAscenceur.setPreferredSize(DimLResuUniv) ;
       LResuUniv.addListSelectionListener(this) ;
     
    	//Zone affichage
        topTextArea = new JTextArea();
    	topTextArea.setEditable(false);
        JScrollPane topScrollPane = new JScrollPane(topTextArea);
        Dimension preferredSize = new Dimension(850, 200);
        topScrollPane.setPreferredSize(preferredSize);
     
     
     
     
    	//Ajout  au niveau du panel
    	this.add(button1) ;
    	this.add(button2) ;
    	this.add(listeAvecAscenseur) ;
    	this.add(LCombiBaseAvecAscenceur) ;
    	this.add(LResuUnivAvecAscenceur) ;
    	this.add(topScrollPane);
     
     
    	//Mise en ecoute du bouton1
    	button1.addActionListener(this);
    	button2.addActionListener(this);
     
       }
     
       public void actionPerformed(ActionEvent e) 
       {
        if (e.getSource() == button1)
    	{
    	  if (e.getActionCommand() == "Go" )
    	  {
    	   if ( liste.getSelectedIndex() == 0) 
    	    {
    		 ChgtListeOffre() ;
     
    		 //cmd1="ls -rtl /universe_log/CNAM50/exp/log/*PB80PEXJOSV020*|tail -1|cut -d: -f2|cut -c4-" ;
    		 //Trait1(cmd1) ;
    		}
    	   else if ( liste.getSelectedIndex() == 1)
    	    {
    		 //Test si le choix a ete fait dans les liste
    		 if ( Shostdep.length() >0 && Choixlcombibase.length() >0 && ChoixResuuniv.length() >0 )
    		   {
    		 cmd3="rsh "+Shostdep+" -l root \"/cadnat/ctige/script/java/test3.sh \\\""+Choixlcombibase+"\\\" \\\""+ChoixResuuniv+"\\\" \"" ;
    		 Trait1(cmd3) ;
    		 //System.out.println(cmd3) ;
    		   }
    		 else 
    		   {
    		     topTextArea.append("Votre choix n est pas complet cliquer dans les liste \n");
    		   }
    		   //Fin Test si le choix a ete fait dans les liste
    		}
    	  }
     
    	//System.out.println("Hello") ;
    	}
       }
       //
     
       //
       public void valueChanged(ListSelectionEvent evt)
       {
       if (evt.getSource() == LResuUniv )
         {
    	 if ( evt.getValueIsAdjusting())
    	     {
    		 ChoixResuuniv=(String)LResuUniv.getSelectedValue() ;
    	 //System.out.println((String)LResuUniv.getSelectedValue() ) ;
    	     }
    	 }
       else if (evt.getSource() == LCombiBase )
          {
          if ( evt.getValueIsAdjusting())
    	  {
    	     System.out.println((String)LCombiBase.getSelectedValue()) ;
    	      Choixlcombibase=(String)LCombiBase.getSelectedValue() ;
    	      Sinstdep=Choixlcombibase.substring(0,6) ;
    		  strip1=Choixlcombibase.split(":") ;
     
    		  Shostdep=strip1[1] ;
    		  Shostarr=strip1[2] ; 
     
    		 cmd2="rsh "+Shostdep+" -l root \"cat /cadnat/save/DS_v6.0.1/log/"+Sinstdep+"/copie_db*|grep \\\"Fin de la procedure Ora_endbackup\\\" |cut -c1-17|tail -10\"" ;
    		 System.out.println(cmd2) ;
             //LResuUniv.removeListSelectionListener(this) ;
    		 //cmd2="rsh 156701a001dbs -l root \"cat /cadnat/save/DS_v6.0.1/log/oo2p80/copie_db*|grep \\\"Fin de la procedure Ora_endbackup\\\" |cut -c1-17|tail -10\"";
    		 Enveloppe.clear();
    		 LResuUniv.clearSelection () ;
    		 Alim_Resu_Univ(cmd2) ;
    		 //LResuUniv.addListSelectionListener(this) ; 
    	  } 		 
     
    	  } 
       }
     
       public void ChgtListeOffre()
       {
         try {
     
    	 	InputStream ips=new FileInputStream(fichier); 
    		InputStreamReader ipsr=new InputStreamReader(ips);
    		BufferedReader br=new BufferedReader(ipsr);
    		String ligne;
    		//Enveloppe2.clear();
    			while ((ligne=br.readLine())!=null){
    			   TabLectureChoix.add(ligne) ;
    				//paramcnx.add(ligne.split("=")) ;
    				Enveloppe2.addElement(ligne) ;
    				System.out.println(ligne);
    				//chaine+=ligne+"\n";
    			}
    			br.close();
     
    	     }
         catch(Exception ex1) {
    	topTextArea.append("Pb execution ") ;
    	topTextArea.append(ex1.getMessage()) ;
    	                     }
       }
     
       public void Trait1(String shell)
       {
       try {
    String[] cmd = { "/bin/sh", "-c", shell };
    //String[] cmd = { "/bin/sh", "-c", "ls -rtl /universe_log/CNAM50/exp/log/*PB80PEXJOSV020*|tail -1|cut -d: -f2|cut -c4-" };
    //String cmd="/cadnat/ctige/script/java/test.sh" ;
    Runtime runtime = Runtime.getRuntime();
    final Process process = runtime.exec(cmd);
     
    // Consommation de la sortie standard de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    			String line = "";
    			try {
    				while((line = reader.readLine()) != null) {
    					// Traitement du flux de sortie de l'application si besoin est
    					topTextArea.append(line+"\n") ;
    				}
    			} finally {
    				reader.close();
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();
     
    // Consommation de la sortie d'erreur de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader4 = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    			String line = "";
    			try {
    				while((line = reader4.readLine()) != null) {
    					// Traitement du flux d'erreur de l'application si besoin est
    					topTextArea.append("\n"+line+"\n") ;
    				}
    			} finally {
    				reader4.close();
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();	
        }
                     catch(Exception e) 
             { 
                  topTextArea.append(e.getMessage()) ;
                  //topTextArea.append(e.printStackTrace()); 
             }  	
       }
     
    public void Alim_Resu_Univ(String shell)
       {
        try {
     
    String[] cmdi = { "/bin/sh", "-c", shell };
    //String[] cmd = { "/bin/sh", "-c", "ls -rtl /universe_log/CNAM50/exp/log/*PB80PEXJOSV020*|tail -1|cut -d: -f2|cut -c4-" };
    //String cmd="/cadnat/ctige/script/java/test.sh" ;
     
    Runtime runtime2 = Runtime.getRuntime();
    final Process process2 = runtime2.exec(cmdi);
     
    // Consommation de la sortie standard de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader2 = new BufferedReader(new InputStreamReader(process2.getInputStream()));
    			String line = "";
    			try {
    			    //Enveloppe.clear();
    				while((line = reader2.readLine()) != null) {
    					// Traitement du flux de sortie de l'application si besoin est
    					//topTextArea.append(line+"\n") ;
    					Enveloppe.addElement(line.substring(0,17)) ;
    				}
     
    			} finally {
    				reader2.close();
     
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();
     
    // Consommation de la sortie d'erreur de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader3 = new BufferedReader(new InputStreamReader(process2.getErrorStream()));
    			String line = "";
    			try {
    				while((line = reader3.readLine()) != null) {
    					// Traitement du flux d'erreur de l'application si besoin est
    					topTextArea.append("\n"+line+"\n") ;
    				}
    			} finally {
    				reader3.close();
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();	
        }
                     catch(Exception e) 
             { 
                  topTextArea.append(e.getMessage()) ;
                  //topTextArea.append(e.printStackTrace()); 
             }   
       }
     
    private static void showgui()
      {
      JFrame bt = new JFrame("Resto_Base") ;
      bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = bt.getContentPane() ;
      c.setLayout(new BorderLayout()) ;
      Ajout_Dbf ma = new Ajout_Dbf() ;
      c.add(ma) ;
      bt.setSize(1400,500) ;
      bt.setVisible(true) ;
      }
     
    public static void main (String [] args)
        {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
       showgui() ;
    		    }
    		    });
        }
     
    }

  4. #4
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Points : 7 163
    Points
    7 163
    Par défaut
    Regarde la Javadoc, particulièrement les méthodes héritées de AbstractListModel.

  5. #5
    Nouveau membre du Club
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Points : 25
    Points
    25
    Par défaut
    Ok, si je comprends bien , il faut que je me créé une nouvelle classe qui etende AbstractListmodel pour utiliser la methode fireContentsChanged

    j'ai essayé un truc du style suivant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
      public class Refreshlist extends AbstractListModel {
     
      public void Modiflist(DefaultListModel element) {
     
             fireContentsChanged(element, 0, element.getSize());
     
    	}
     
      }
    Mais ça ne fonctionne pas, , je ne maitrise pas encore bien tous les concepts java

  6. #6
    Nouveau membre du Club
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Points : 25
    Points
    25
    Par défaut
    Bonjour,

    J'ai suivi les conseils ... j'utilise les méthodes fire... pour mettre a jour ma liste,

    par contre je rencontre toujours le même pb( c'est un peu mieux) de rafraichissement.
    pour rappel, je mets à jour une liste par rapport à une autre liste (un clic dans la 1ere liste met a jour la 2ème liste).

    Si qq pouvait me donner qq conseils, cela fait qq semaines que je galère.

    Merci pour vos réponses.

    voici 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
    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
     
    import javax.swing.*;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import java.awt.Dimension;
    import java.awt.Color;
    import java.util.Vector ;
    import javax.swing.event.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseListener;
    import java.awt.* ;
    import java.io.*;
    import java.sql.*;
    //import oracle.jdbc.driver.*;
    import java.lang.* ;
    import java.util.ArrayList ;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.SortedSet;
    import java.util.TreeSet;
     
    //import javax.swing.AbstractListModel;
     
    class SortedListModel extends AbstractListModel {
      SortedSet<Object> model;
     
      public SortedListModel() {
        model = new TreeSet<Object>();
      }
     
      public int getSize() {
        return model.size();
      }
     
      public Object getElementAt(int index) {
        return model.toArray()[index];
      }
     
      public void add(Object element) {
        if (model.add(element)) {
          fireContentsChanged(this, 0, getSize());
        }
      }
     
      public void addAll(Object elements[]) {
        Collection<Object> c = Arrays.asList(elements);
        model.addAll(c);
        fireContentsChanged(this, 0, getSize());
      }
     
      public void clear() {
        model.clear();
        fireContentsChanged(this, 0, getSize());
      }
     
      public boolean contains(Object element) {
        return model.contains(element);
      }
     
      public Object firstElement() {
        return model.first();
      }
     
      public Iterator iterator() {
        return model.iterator();
      }
     
      public Object lastElement() {
        return model.last();
      }
     
      public boolean removeElement(Object element) {
        boolean removed = model.remove(element);
        if (removed) {
          fireContentsChanged(this, 0, getSize());
        }
        return removed;
      }
    }
     
    //class TestLogic_Resto extends JPanel implements  ActionListener,ListSelectionListener
    class TestLogic_Resto extends JPanel implements ListSelectionListener
    {
    SortedListModel sourceListModel,cibleListModel;
    JList sourceList,cibleList;
    JScrollPane AvecAscsourceList,AvecAsccibleList ;
    Dimension DimsourceList,DimcibleList;
    //DefaultListModel Enveloppe ;
    JTextArea topTextArea ;
     
    String ChoixsourceList ;
     
    String Sinstdep,Shostdep,Shostarr,Slogflashcopie,cmd2 ;
    String[] strip1={"","",""} ;
     
     public TestLogic_Resto() {
     
        //liste source
        sourceListModel = new SortedListModel(); // SortedListModel
        sourceList = new JList(sourceListModel); //JList
    	AvecAscsourceList = new JScrollPane(sourceList) ;
    	DimsourceList = new Dimension(90,150) ;
    	AvecAscsourceList.setPreferredSize(DimsourceList) ;
    	sourceList.addListSelectionListener(this) ;
    	//liste cible
    	cibleListModel = new SortedListModel(); // SortedListModel
    	cibleList = new JList(cibleListModel); //JList
    	AvecAsccibleList = new JScrollPane(cibleList) ;
    	cibleList.addListSelectionListener(this) ;
     
     
     
    		//Zone affichage
        topTextArea = new JTextArea();
    	topTextArea.setEditable(false);
        JScrollPane topScrollPane = new JScrollPane(topTextArea);
        Dimension preferredSize = new Dimension(850, 200);
        topScrollPane.setPreferredSize(preferredSize);
    //
        this.add(AvecAscsourceList) ;
    	this.add(AvecAsccibleList) ;
        this.add(topScrollPane) ;
    	addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2q80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
    	addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2a80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
    	addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2f80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
    	addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2t80@02fhob:156701a001dbs:156701a02fhob:/cadnat/save/DS_v6.0.1/log/" });
    	addSourceElements(sourceListModel,new String[] { "ou7p80@001dbs->ou7q80@033ora:156701a001dbs:156701a033ora:/cadnat/save/DS_v6.0.1/log/" });
    	//topTextArea.append("toto") ;
     
     }
        public void valueChanged(ListSelectionEvent evt)
       {
     
        if (evt.getSource() == sourceList )
          {
    	   if ( evt.getValueIsAdjusting())
    	    {
    		  ChoixsourceList=(String)sourceList.getSelectedValue() ;
    		  Sinstdep=ChoixsourceList.substring(0,6) ;
    		  strip1=ChoixsourceList.split(":") ;
    		  Shostdep=strip1[1] ;
    		  Shostarr=strip1[2] ; 
    		  Slogflashcopie=strip1[3] ;
    		  cmd2="rsh "+Shostdep+" -l root \"cat "+Slogflashcopie+Sinstdep+"/copie_db*|grep \\\"Fin de la procedure Ora_endbackup\\\" |cut -c1-17|tail -10\"" ;
    		  clearListModel(cibleListModel) ;
    		  Alim_Resu_Univ(cmd2) ;
    	     //addSourceElements(cibleListModel,new String[] {"vide"}) ;
     
    	    }
    	  }
       }
     
       public void addSourceElements(SortedListModel malistemodel,ListModel newValue) {
        fillListModel(malistemodel, newValue);
      }
     
      public void addSourceElements(SortedListModel malistemodel,Object newValue[]) {
        fillListModel(malistemodel, newValue);
      }
       private void fillListModel(SortedListModel model, ListModel newValues) {
        int size = newValues.getSize();
        for (int i = 0; i < size; i++) {
          model.add(newValues.getElementAt(i));
        }
      }
     
       private void fillListModel(SortedListModel model, Object newValues[]) {
        model.addAll(newValues);
      }
     
        public void clearListModel(SortedListModel model) {
        model.clear();
      }
     
     
    //
    public void Alim_Resu_Univ(String shell)
       {
        try {
     
    String[] cmdi = { "/bin/sh", "-c", shell };
    //String[] cmd = { "/bin/sh", "-c", "ls -rtl /universe_log/CNAM50/exp/log/*PB80PEXJOSV020*|tail -1|cut -d: -f2|cut -c4-" };
    //String cmd="/cadnat/ctige/script/java/test.sh" ;
     
    Runtime runtime2 = Runtime.getRuntime();
    final Process process2 = runtime2.exec(cmdi);
     
    // Consommation de la sortie standard de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader2 = new BufferedReader(new InputStreamReader(process2.getInputStream()));
    			String line = "";
    			try {
    			    //Enveloppe.clear();
    				while((line = reader2.readLine()) != null) {
    					// Traitement du flux de sortie de l'application si besoin est
    					//topTextArea.append(line+"\n") ;
    					addSourceElements(cibleListModel,new String[] {line.substring(0,17)}) ;
    					//Enveloppe.addElement(line.substring(0,17)) ;
    				}
    				//ChoixResuuniv="" ;
    				//
    				//LResuUniv.validate() ;
    				//
     
    			} finally {
    				reader2.close();
     
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();
     
    // Consommation de la sortie d'erreur de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader3 = new BufferedReader(new InputStreamReader(process2.getErrorStream()));
    			String line = "";
    			try {
    				while((line = reader3.readLine()) != null) {
    					// Traitement du flux d'erreur de l'application si besoin est
    					topTextArea.append("\n"+line+"\n") ;
    				}
    			} finally {
    				reader3.close();
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();	
        }
    	                 catch(Exception e) 
             { 
                  topTextArea.append(e.getMessage()) ;
                  //topTextArea.append(e.printStackTrace()); 
             }   
       }
     
    private static void showgui()
      {
      JFrame bt = new JFrame("Resto_Base") ;
      bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = bt.getContentPane() ;
      c.setLayout(new BorderLayout()) ;
      TestLogic_Resto ma = new TestLogic_Resto() ;
      c.add(ma) ;
      bt.setSize(1400,500) ;
      bt.setVisible(true) ;
      }
     
    public static void main (String [] args)
        {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
       showgui() ;
    		    }
    		    });
        }
     
    }

  7. #7
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Points : 7 163
    Points
    7 163
    Par défaut
    Tu devrais sortir un code simple et compilable/testable qui reproduise le problème.

  8. #8
    Nouveau membre du Club
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Points : 25
    Points
    25
    Par défaut Rafraichissement d'une liste
    Je clic dans une première liste qui declanche un thread (shell) pour mettre à jour la 2ème liste.


    Voici 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
    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
     
    import javax.swing.*;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import java.awt.Dimension;
    import java.awt.Color;
    import java.util.Vector ;
    import javax.swing.event.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseListener;
    import java.awt.* ;
    import java.io.*;
    import java.sql.*;
    //import oracle.jdbc.driver.*;
    import java.lang.* ;
    import java.util.ArrayList ;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.SortedSet;
    import java.util.TreeSet;
     
    //import javax.swing.AbstractListModel;
     
    class SortedListModel extends AbstractListModel {
      SortedSet<Object> model;
     
      public SortedListModel() {
        model = new TreeSet<Object>();
      }
     
      public int getSize() {
        return model.size();
      }
     
      public Object getElementAt(int index) {
        return model.toArray()[index];
      }
     
      public void add(Object element) {
        if (model.add(element)) {
          fireContentsChanged(this, 0, getSize());
        }
      }
     
      public void addAll(Object elements[]) {
        Collection<Object> c = Arrays.asList(elements);
        model.addAll(c);
        fireContentsChanged(this, 0, getSize());
      }
     
      public void clear() {
        model.clear();
        fireContentsChanged(this, 0, getSize());
      }
     
      public boolean contains(Object element) {
        return model.contains(element);
      }
     
      public Object firstElement() {
        return model.first();
      }
     
      public Iterator iterator() {
        return model.iterator();
      }
     
      public Object lastElement() {
        return model.last();
      }
     
      public boolean removeElement(Object element) {
        boolean removed = model.remove(element);
        if (removed) {
          fireContentsChanged(this, 0, getSize());
        }
        return removed;
      }
    }
     
    //class TestLogic_Resto extends JPanel implements  ActionListener,ListSelectionListener
    class TestLogic_Resto extends JPanel implements ListSelectionListener
    {
    SortedListModel sourceListModel,cibleListModel;
    JList sourceList,cibleList;
    JScrollPane AvecAscsourceList,AvecAsccibleList ;
    Dimension DimsourceList,DimcibleList;
    //DefaultListModel Enveloppe ;
    JTextArea topTextArea ;
     
    String ChoixsourceList ;
     
    String Sinstdep,Shostdep,Shostarr,Slogflashcopie,cmd2 ;
    String[] strip1={"","",""} ;
     
     public TestLogic_Resto() {
     
        //liste source
        sourceListModel = new SortedListModel(); // SortedListModel
        sourceList = new JList(sourceListModel); //JList
    	AvecAscsourceList = new JScrollPane(sourceList) ;
    	DimsourceList = new Dimension(90,150) ;
    	AvecAscsourceList.setPreferredSize(DimsourceList) ;
    	sourceList.addListSelectionListener(this) ;
    	//liste cible
    	cibleListModel = new SortedListModel(); // SortedListModel
    	cibleList = new JList(cibleListModel); //JList
    	AvecAsccibleList = new JScrollPane(cibleList) ;
    	cibleList.addListSelectionListener(this) ;
     
     
     
    		//Zone affichage
        topTextArea = new JTextArea();
    	topTextArea.setEditable(false);
        JScrollPane topScrollPane = new JScrollPane(topTextArea);
        Dimension preferredSize = new Dimension(850, 200);
        topScrollPane.setPreferredSize(preferredSize);
    //
        this.add(AvecAscsourceList) ;
    	this.add(AvecAsccibleList) ;
     
    	this.add(topScrollPane) ;
    	addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2q80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
    	addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2a80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
    	addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2f80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/" });
    	addSourceElements(sourceListModel,new String[] { "oo2p80@001dbs->oo2t80@02fhob:156701a001dbs:156701a02fhob:/cadnat/save/DS_v6.0.1/log/" });
    	addSourceElements(sourceListModel,new String[] { "ou7p80@001dbs->ou7q80@033ora:156701a001dbs:156701a033ora:/cadnat/save/DS_v6.0.1/log/" });
    	//topTextArea.append("toto") ;
     
     }
        public void valueChanged(ListSelectionEvent evt)
       {
     
        if (evt.getSource() == sourceList )
          {
    	   if ( evt.getValueIsAdjusting())
    	    {
    		  ChoixsourceList=(String)sourceList.getSelectedValue() ;
    		  Sinstdep=ChoixsourceList.substring(0,6) ;
    		  strip1=ChoixsourceList.split(":") ;
    		  Shostdep=strip1[1] ;
    		  Shostarr=strip1[2] ; 
    		  Slogflashcopie=strip1[3] ;
    		  cmd2="rsh "+Shostdep+" -l root \"cat "+Slogflashcopie+Sinstdep+"/copie_db*|grep \\\"Fin de la procedure Ora_endbackup\\\" |cut -c1-17|tail -10\"" ;
    		  clearListModel(cibleListModel) ;
    		  Alim_Resu_Univ(cmd2) ;
     
     
     
    	     //addSourceElements(cibleListModel,new String[] {"vide"}) ;
     
    	    }
    	  }
       }
     //
    /*
        public void addSourceElements(ListModel newValue) {
        fillListModel(sourceListModel, newValue);
      }
      
      public void addSourceElements(Object newValue[]) {
        fillListModel(sourceListModel, newValue);
      }
      
     
        public void addCibleElements(ListModel newValue) {
        fillListModel(cibleListModel, newValue);
      }
      
      public void addCibleElements(Object newValue[]) {
        fillListModel(cibleListModel, newValue);
      }
      */
     
       public void addSourceElements(SortedListModel malistemodel,ListModel newValue) {
        fillListModel(malistemodel, newValue);
      }
     
      public void addSourceElements(SortedListModel malistemodel,Object newValue[]) {
        fillListModel(malistemodel, newValue);
      }
     
       private void fillListModel(SortedListModel model, ListModel newValues) {
        int size = newValues.getSize();
        for (int i = 0; i < size; i++) {
          model.add(newValues.getElementAt(i));
        }
      }
     
       private void fillListModel(SortedListModel model, Object newValues[]) {
        model.addAll(newValues);
      }
     
        public void clearListModel(SortedListModel model) {
        model.clear();
      }
     
     
    //
    public void Alim_Resu_Univ(String shell)
       {
        try {
     
    String[] cmdi = { "/bin/sh", "-c", shell };
    //String[] cmd = { "/bin/sh", "-c", "ls -rtl /universe_log/CNAM50/exp/log/*PB80PEXJOSV020*|tail -1|cut -d: -f2|cut -c4-" };
    //String cmd="/cadnat/ctige/script/java/test.sh" ;
     
    Runtime runtime2 = Runtime.getRuntime();
    final Process process2 = runtime2.exec(cmdi);
     
    // Consommation de la sortie standard de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader2 = new BufferedReader(new InputStreamReader(process2.getInputStream()));
    			String line = "";
    			try {
    			    //Enveloppe.clear();
    				while((line = reader2.readLine()) != null) {
    					// Traitement du flux de sortie de l'application si besoin est
    					//topTextArea.append(line+"\n") ;
    					addSourceElements(cibleListModel,new String[] {line.substring(0,17)}) ;
    					//Enveloppe.addElement(line.substring(0,17)) ;
    				}
     
    				//ChoixResuuniv="" ;
    				//
    				//LResuUniv.validate() ;
    				//
     
    			} finally {
    				reader2.close();
     
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();
     
    // Consommation de la sortie d'erreur de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader3 = new BufferedReader(new InputStreamReader(process2.getErrorStream()));
    			String line = "";
    			try {
    				while((line = reader3.readLine()) != null) {
    					// Traitement du flux d'erreur de l'application si besoin est
    					topTextArea.append("\n"+line+"\n") ;
    				}
    			} finally {
    				reader3.close();
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();	
        }
    	                 catch(Exception e) 
             { 
                  topTextArea.append(e.getMessage()) ;
                  //topTextArea.append(e.printStackTrace()); 
             }   
       }
    //
     
    private static void showgui()
      {
      JFrame bt = new JFrame("Resto_Base") ;
      bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = bt.getContentPane() ;
      c.setLayout(new BorderLayout()) ;
      TestLogic_Resto ma = new TestLogic_Resto() ;
      c.add(ma) ;
      bt.setSize(1400,500) ;
      bt.setVisible(true) ;
      }
     
    public static void main (String [] args)
        {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
       showgui() ;
    		    }
    		    });
        }
     
    }
    j'ai aussi le remontée d'erreur suivante :

    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
     
    Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
            at java.util.TreeMap$AbstractMapIterator.makeNext(TreeMap.java:5794)
            at java.util.TreeMap$UnboundedKeyIterator.next(TreeMap.java:5896)
            at java.util.AbstractCollection.toArray(AbstractCollection.java:304)
            at SortedListModel.getElementAt(TestLogic_Resto.java:38)
            at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1343)
            at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1294)
            at javax.swing.plaf.basic.BasicListUI.getPreferredSize(BasicListUI.java:561)
            at javax.swing.JComponent.getPreferredSize(JComponent.java:1646)
            at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:781)
            at java.awt.Container.layout(Container.java:1433)
            at java.awt.Container.doLayout(Container.java:1422)
            at java.awt.Container.validateTree(Container.java:1519)
            at java.awt.Container.validate(Container.java:1492)
            at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:681)
            at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:136)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:221)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:609)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Comment expliquer et résoudre cette exception ?

  9. #9
    Nouveau membre du Club
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Points : 25
    Points
    25
    Par défaut
    Je pense que j'ai compris l' exception qui est levée, mais je n'arrive pas à la résoudre .

    le pb vient de ma classe SortedListModel j'utilise la classe TreeSet qui rentre en conflit avec la ligne suivante :AvecAsccibleList = new JScrollPane(cibleList) ;

    lorsque ma liste est mise à jour.

    comment enlever la classe TreeSet ?

  10. #10
    Nouveau membre du Club
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Points : 25
    Points
    25
    Par défaut
    J'ai réussi à résoudre mon problème , je me suis fortement inspiré d'un article de romain Vimont (merci à lui) concernant les MVC.

    désormais lorsque je clic dans la première liste, la deuxième se charge correctement à chaque fois et quelque soit sa taille .

    Voici le code pour ceux que cela intéresse.

    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
     
    import javax.swing.*;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import java.awt.Dimension;
    import java.awt.Color;
    //import java.awt.List;
    import java.util.Vector ;
    import javax.swing.event.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseListener;
    import java.util.EventListener;
    import java.awt.* ;
    import java.io.*;
    import java.sql.*;
    //import oracle.jdbc.driver.*;
    import java.lang.* ;
    import java.util.ArrayList ;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.List ;
     
    //public class PersonnesListModel extends AbstractListModel { 
    class PersonnesListModel extends AbstractListModel { 
     
    private List<String> list ;
    private final Controller controller = new Controller();
     
     
    public PersonnesListModel ( Personnes personnes ) {
    list = new ArrayList <String>();
    for ( int i=0; i < personnes.getPersonnesCount(); i++) {
     
     
    list.add(personnes.getPersonne(i)); 
     
    }
    personnes.addPersonnesListener(controller); 
     
    } 
    //
     
    //
     
    @Override
    public String getElementAt(int index) {
    return list.get(index);
    } 
     
    @Override
    public int getSize () {
    return list.size ();
    } 
     
    private class Controller implements PersonnesListener { 
     
    public void personneAjoutee ( final int index , final String name) {
    Runnable runnable = new Runnable() {
     
    public void run() {
    list.add(index , name); 
    fireIntervalAdded (PersonnesListModel.this , index , index ); 
    }
    } ; 
    if ( SwingUtilities.isEventDispatchThread ()) {
     
    runnable.run(); 
     
    } else {
     
    SwingUtilities.invokeLater(runnable); 
     
    }
    }
     
     
    public void personneSupprimee ( final int index , final String name) {
    Runnable runnable = new Runnable() {
     
    public void run() {
    list.remove(index); 
    fireIntervalAdded (PersonnesListModel.this , index , index ); 
     
    }
    } ;
     
    if ( SwingUtilities.isEventDispatchThread ()) {
    runnable .run ();
     
    } else {
     
    SwingUtilities.invokeLater(runnable); 
     
    }
    }
    //
    public void personneClear () {
    Runnable runnable = new Runnable() {
     
    public void run() {
    list.clear(); 
    fireIntervalAdded (PersonnesListModel.this , 0 , 0 ); 
     
    }
    } ;
     
    if ( SwingUtilities.isEventDispatchThread ()) {
    runnable .run ();
     
    } else {
     
    SwingUtilities.invokeLater(runnable); 
     
    }
    }
    //
     
     
    } 
     
     
     
    }
     
    //
    //public interface PersonnesListener extends EventListener {
    interface PersonnesListener extends EventListener {
    void personneAjoutee ( int index , String name); 
     
    void personneSupprimee ( int index , String name); 
     
    //
    void personneClear ();
    //
     
    }
    //
    //public class Personnes { 
    class Personnes { 
     
    private List<String> personnes ;
    private final EventListenerList listeners = new EventListenerList();
     
    public Personnes ()
    {
    personnes = new ArrayList<String > (); 
    } 
     
    public String getPersonne( int index ) 
    {
    return personnes.get(index ); 
    } 
     
    public int getPersonnesCount() 
    {
    return personnes.size(); 
    } 
    /*
    public void clearPersonne()
    {
    personnes.clear() ;
    fireContentsChanged(this, 0, 0);
    }
    */
    public void addPersonne(String name) 
    {
    personnes.add(name);
    firePersonneAjoutee(personnes.size() - 1, name);
    } 
     
    public void removePersonne(String name) 
    {
    int index = personnes.indexOf(name);
    if ( index >= 0)
    {
    personnes.remove(index );
    firePersonneSupprimee(index , name);
    }
    }
    //
    public void clearPersonne() 
    {
    personnes.clear();
    firePersonneClear();
    }
    //
     
    public PersonnesListener[] getPersonnesListeners() {
    return listeners.getListeners(PersonnesListener.class );
    } 
     
    public void addPersonnesListener(PersonnesListener listener) {
    listeners.add(PersonnesListener.class,listener );
    } 
     
    public void removePersonnesListener(PersonnesListener listener) {
    listeners.remove(PersonnesListener.class,listener );
    }
     
    /*
    public void clearPersonnesListener(PersonnesListener listener) {
    listeners.clear(PersonnesListener.class,listener );
    }
    */ 
     
    protected void firePersonneAjoutee( int index , String name) {
    for (PersonnesListener l : getPersonnesListeners ()) {
    l.personneAjoutee(index, name); 
    }
    }
     
    protected void firePersonneSupprimee ( int index , String name) {
    for (PersonnesListener l : getPersonnesListeners ()) {
     
    l.personneSupprimee(index, name); 
    }
    }
    //
    protected void firePersonneClear() {
    for (PersonnesListener l : getPersonnesListeners ()) {
    l.personneClear(); 
    }
    }
    //
     
    }
     
    //
    class SuperLogic_Resto extends JPanel implements ListSelectionListener
    {
    Personnes listesourcepersonnes,listeciblepersonnes ;
    PersonnesListModel sourceListModel,cibleListModel;
    JList sourceList,cibleList;
    JScrollPane AvecAscsourceList,AvecAsccibleList ;
    Dimension DimsourceList,DimcibleList;
    //DefaultListModel Enveloppe ;
    JTextArea topTextArea ;
     
    String ChoixsourceList ;
     
    String Sinstdep,Shostdep,Shostarr,Slogflashcopie,cmd2 ;
    String[] strip1={"","",""} ;
     
     
     public SuperLogic_Resto() {
     
        //liste source
     
        listesourcepersonnes = new Personnes() ;
        sourceListModel = new PersonnesListModel(listesourcepersonnes); // SortedListModel
        sourceList = new JList(sourceListModel); //JList
    	AvecAscsourceList = new JScrollPane(sourceList) ;
    	DimsourceList = new Dimension(90,150) ;
    	AvecAscsourceList.setPreferredSize(DimsourceList) ; 
    	sourceList.addListSelectionListener(this) ;
     
    	//liste cible
    	listeciblepersonnes = new Personnes() ;
        cibleListModel = new PersonnesListModel(listeciblepersonnes); // SortedListModel
        cibleList = new JList(cibleListModel); //JList
    	AvecAsccibleList = new JScrollPane(cibleList) ;
    	DimcibleList = new Dimension(90,150) ;
    	AvecAsccibleList.setPreferredSize(DimcibleList) ; 
     
     
     
     
     
     
    		//Zone affichage
        topTextArea = new JTextArea();
    	topTextArea.setEditable(false);
        JScrollPane topScrollPane = new JScrollPane(topTextArea);
        Dimension preferredSize = new Dimension(850, 200);
        topScrollPane.setPreferredSize(preferredSize);
    //
        this.add(AvecAscsourceList) ;
    	this.add(AvecAsccibleList) ;
     
     
    	this.add(topScrollPane) ;
    	//topTextArea.append("toto") ;
     
    	listesourcepersonnes.addPersonne("oo2p80@001dbs->oo2q80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/") ;
    	listesourcepersonnes.addPersonne("oo2p80@001dbs->oo2a80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/") ;
    	listesourcepersonnes.addPersonne("oo2p80@001dbs->oo2f80@001dbs:156701a001dbs:156701a001dbs:/cadnat/save/DS_v6.0.1/log/") ;
    	listesourcepersonnes.addPersonne("oo2p80@001dbs->oo2t80@02fhob:156701a001dbs:156701a02fhob:/cadnat/save/DS_v6.0.1/log/") ;
    	listesourcepersonnes.addPersonne("ou7p80@001dbs->ou7q80@033ora:156701a001dbs:156701a033ora:/cadnat/save/DS_v6.0.1/log/") ;
     
     }
     
     //
        public void valueChanged(ListSelectionEvent evt)
       {
     
        if (evt.getSource() == sourceList )
          {
    	   if ( evt.getValueIsAdjusting())
    	    {
    		  ChoixsourceList=(String)sourceList.getSelectedValue() ;
    		  Sinstdep=ChoixsourceList.substring(0,6) ;
    		  strip1=ChoixsourceList.split(":") ;
    		  Shostdep=strip1[1] ;
    		  Shostarr=strip1[2] ; 
    		  Slogflashcopie=strip1[3] ;
    		  cmd2="rsh "+Shostdep+" -l root \"cat "+Slogflashcopie+Sinstdep+"/copie_db*|grep \\\"Fin de la procedure Ora_endbackup\\\" |cut -c1-17|tail -10\"" ;
     
    		  Alim_Resu_Univ(cmd2) ;
     
     
     
    	     //addSourceElements(cibleListModel,new String[] {"vide"}) ;
     
    	    }
    	  }
       }
     
    //
    public void Alim_Resu_Univ(String shell)
       {
        try {
     
    String[] cmdi = { "/bin/sh", "-c", shell };
    //String[] cmd = { "/bin/sh", "-c", "ls -rtl /universe_log/CNAM50/exp/log/*PB80PEXJOSV020*|tail -1|cut -d: -f2|cut -c4-" };
    //String cmd="/cadnat/ctige/script/java/test.sh" ;
     
    Runtime runtime2 = Runtime.getRuntime();
    final Process process2 = runtime2.exec(cmdi);
     
    // Consommation de la sortie standard de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader2 = new BufferedReader(new InputStreamReader(process2.getInputStream()));
    			String line = "";
    			try {
    			    //Enveloppe.clear();
    				//cibleListModel.clear() ;
    				listeciblepersonnes.clearPersonne() ;
    				while((line = reader2.readLine()) != null) {
    					// Traitement du flux de sortie de l'application si besoin est
    					//topTextArea.append(line+"\n") ;
    					listeciblepersonnes.addPersonne(line.substring(0,17)) ;
    					//Enveloppe.addElement(line.substring(0,17)) ;
    				}
     
    				//ChoixResuuniv="" ;
    				//
    				//LResuUniv.validate() ;
    				//
     
    			} finally {
    				reader2.close();
     
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();
     
    // Consommation de la sortie d'erreur de l'application externe dans un Thread separe
    new Thread() {
    	public void run() {
    		try {
    			BufferedReader reader3 = new BufferedReader(new InputStreamReader(process2.getErrorStream()));
    			String line = "";
    			try {
    				while((line = reader3.readLine()) != null) {
    					// Traitement du flux d'erreur de l'application si besoin est
    					topTextArea.append("\n"+line+"\n") ;
    				}
    			} finally {
    				reader3.close();
    			}
    		} catch(IOException ioe) {
    			ioe.printStackTrace();
    		}
    	}
    }.start();	
        }
    	                 catch(Exception e) 
             { 
                  topTextArea.append(e.getMessage()) ;
                  //topTextArea.append(e.printStackTrace()); 
             }   
       }
    //
     
    private static void showgui()
      {
      JFrame bt = new JFrame("Resto_Base") ;
      bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = bt.getContentPane() ;
      c.setLayout(new BorderLayout()) ;
      SuperLogic_Resto ma = new SuperLogic_Resto() ;
      c.add(ma) ;
      bt.setSize(1400,500) ;
      bt.setVisible(true) ;
      }
     
    public static void main (String [] args)
        {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
       showgui() ;
    		    }
    		    });
        }
     
    }

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 07/10/2014, 10h28
  2. Réponses: 20
    Dernier message: 27/07/2010, 15h52
  3. Réponses: 2
    Dernier message: 05/10/2007, 23h49
  4. Réponses: 3
    Dernier message: 10/05/2007, 07h43
  5. Réponses: 3
    Dernier message: 08/10/2005, 00h02

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