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 :

JtextArea Affichage du flux de sortie


Sujet :

AWT/Swing Java

  1. #1
    Membre averti
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Par défaut JtextArea Affichage du flux de sortie
    Bonjour,

    Je souhaite afficher dans un JtextArea par exemple le résultat en sortie d'une requête sql.

    Tout marche bien avec la fonction append() si la sortie ne fait que quelques lignes au-dela l'affichage est illisble.

    J'ai essayé un repaint() mais cela ne marche pas.

    Quelqu'un a t'il une idée ?

    voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    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
     
    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.*;
     
    //
    class InstPkg extends JPanel {
     
    //Variables
    JTextArea topTextArea ;
    ClientSsh ssh1 ;
    //
    public InstPkg() {
     
    		//Zone affichage
        topTextArea = new JTextArea();
    	topTextArea.setEditable(false);
        JScrollPane topScrollPane = new JScrollPane(topTextArea);
        Dimension preferredSize = new Dimension(1100, 400);
        topScrollPane.setPreferredSize(preferredSize);
    	   //Ajout au niveau du panel
    	this.add(topScrollPane) ;
    	ClientSsh ssh1= new ClientSsh(topTextArea) ;
    	ssh1.Lecture_Fic_Cnx("/cadnat/script/java/outils/ssh/cmd.txt") ;
    	topScrollPane.repaint() ;
     
    }
     
     
    private static void showgui()
      {
      JFrame bt = new JFrame("Installation de Package Version 1.0 ") ;
      bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = bt.getContentPane() ;
      c.setLayout(new BorderLayout()) ;
      InstPkg  ma = new InstPkg () ;
      c.add(ma) ;
      bt.setSize(1200,800) ;
      bt.setVisible(true) ;
      }
     
    public static void main (String [] args)
        {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
       showgui() ;
    		    }
    		    });
        }
    }

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Que veut dire l'affichage illisible ?
    Si c'est un problème de scroll, c'est à toi de déplacer le scroll vers la partie de ton textarea que tu souhaites montrer.

  3. #3
    Membre averti
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Par défaut
    Affichage illisible veut dire que lorsque je remonte le scroll pour visualiser les lignes "ecoulées", Jtextarea devient noir .

  4. #4
    Membre chevronné Avatar de Ceddoc
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2009
    Messages
    493
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2009
    Messages : 493
    Par défaut
    Tu as quel volume de données? Quel nombre de ligne?

  5. #5
    Membre averti
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Par défaut
    C'est très variable( car c'est le résultat de commande ssh), mais disons que plus de 150 lignes cela ne fonctionne plus.

  6. #6
    Membre chevronné Avatar de Ceddoc
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2009
    Messages
    493
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2009
    Messages : 493
    Par défaut
    Tu joues déjà avec les cursors? Tu fais quoi dans ta classe SShClient?

  7. #7
    Membre averti
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Par défaut
    Dans la classe SshClient, je passe des commande ssh via un fichier contenant les dites commandes et je récupère le flux de sortie pour l'afficher dans le Jtextarea.

    Mais je ne pense pas que le pb vienne de cette classe, car même si je ne l'utilise pas si j'alimente un JtextArea par une simple lecture d'un fichier contenant plus de 150 lignes, j'ai le même pb.

    Voici quand même le code de SshClient :
    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
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.FileInputStream;
    import java.util.Scanner; 
    import javax.swing.JTextArea;
     
    import com.jcraft.jsch.ChannelExec;
    import com.jcraft.jsch.JSch;
    import com.jcraft.jsch.Session;
     
     
     
    public class ClientSsh {
        public static Session oSession = null;
    	JSch jsch ;
        String sCommandeRecupSession ;
    	String FichierALire  ;
    	Scanner LectureClavier ;
    	JTextArea textarea ;
    	public ClientSsh(JTextArea I_jtarea)
    	{
    	textarea = I_jtarea ;
    	}
    	/*
        public static void main(String[] arg) {
            //String sCommandeRecupSession = ". /app/user/.profile;sqlplus system/manager@demoweb \n set heading on pages 32767 lin 32767 trims ON; \n select count(*) as SESSION_NBR from v$session s; \n select s.sid ||'¤'|| s.serial# ||'¤'|| s.osuser ||'¤'|| s.program ||'¤'|| s.status as SESSION_VALEUR from v$session s; \n exit; \n exit; \n";
    		//String sCommandeRecupSession = ". /app/user/.profile;\n sqlplus / as sysdba @test2.sql\n ";
     
            try {
     
    		ClientSsh test = new ClientSsh() ;
    		//test.Cnx_Ssh("user","hostname","password") ;
    		test.Lecture_Fic_Cnx("/cadnat/ctige/script/java/outils/ssh/cmd.txt") ;
     
            } catch (Exception e) {
                System.out.println(e);
            }
        } */
     
        public int executeCommand(String command) {
            int exitCode = -1;
            ChannelExec channel = null;
    		BufferedReader stdoutReader = null;
            BufferedReader stderrReader = null;
    		String line ;
            try {
                channel = (ChannelExec) oSession.openChannel("exec");
     
                channel.setCommand(command + "\n");
     
                InputStream stdout = channel.getInputStream();
                InputStream stderr = channel.getErrStream();
     
                channel.connect();
     
                stdoutReader = new BufferedReader(new InputStreamReader(stdout));
                stderrReader = new BufferedReader(new InputStreamReader(stderr));
     
                //while (stdoutReader.read() != -1) {
                   while ((line = stdoutReader.readLine()) != null) {
                    //System.out.println(stdoutReader.readLine());
    				//System.out.println(line) ;
    				textarea.append(line+"\n") ;
    				textarea.repaint() ;
    				}
     
                exitCode = channel.getExitStatus();
     
                return exitCode;
            } catch (IOException e) {
                System.out.println("Cannot execute remote command: " + command
                        + " : " + e.getMessage());
            } catch (Exception e) {
                System.out.println("Cannot execute remote command: " + command
                        + " : " + e.getMessage());
            } finally {
                try {
                    stdoutReader.close();
                    stderrReader.close();
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
                if (channel != null) {
                    channel.disconnect();
                }
            }
            return exitCode;
        }
    //
    public void Lecture_Fic_Cnx(String ficparamcnx)
    {
    			String ligne;
    			String chaine="" ;
     
     
    	try {
    			InputStream ips=new FileInputStream(ficparamcnx); 
    			InputStreamReader ipsr=new InputStreamReader(ips);
    			BufferedReader br=new BufferedReader(ipsr);
     
    			LectureClavier = new Scanner(System.in);
    			sCommandeRecupSession=". /app/user/.profile;" ;
    			while ((ligne=br.readLine())!=null){
     
    			  if((ligne.substring(0,1)).equals("#")) {
    			  //System.out.println("deb "+sCommandeRecupSession+" fin");
     
    			  Cnx_Ssh("user","hostname","password",sCommandeRecupSession) ;
    			  System.out.println("\n"+"Voulez vous continuer:");
    			  String reponse = LectureClavier.nextLine();
    			   if (reponse.equals("n") ) {
    			   System.exit(0);
    			    }
    				//System.out.println("deb "+sCommandeRecupSession+" fin");
    				sCommandeRecupSession=". /app/user/.profile;" ;
    				ligne="" ;
    			   }
     
    				sCommandeRecupSession=sCommandeRecupSession+"\n"+ligne ;
    				//System.out.println("deb "+sCommandeRecupSession+" fin");
    				//System.out.println(ligne);
     
    			}
     
    			Cnx_Ssh("user","hostname","password",sCommandeRecupSession) ;
    			//System.out.println("deb "+sCommandeRecupSession+" fin");
    			br.close(); 
     
     
    		}	
     
            catch(Exception er) {
    	System.out.println("Pb execution ") ;
    	er.printStackTrace() ;
     
    	System.out.println(er.getMessage()) ;
    			   }
     
    }
    //	
    //
    public void Cnx_Ssh(String I_user,String I_hostname,String I_password,String I_cmdapasser)
    {
     //sCommandeRecupSession = ". /app/user/.profile;sqlplus user/password<<EOF \n select * from cat ;\n exit ;\n EOF \n";
            try {
                jsch = new JSch();
                //oSession = jsch.getSession("myuser", "localhost", 22);
                //oSession.setPassword("pwd");
                oSession = jsch.getSession(I_user, I_hostname, 22);
    			oSession.setPassword(I_password);
     
                java.util.Properties config = new java.util.Properties();
                config.put("StrictHostKeyChecking", "no");
                oSession.setConfig(config);
     
                oSession.connect();
     
                executeCommand(I_cmdapasser);
     
                oSession.disconnect();
            } catch (Exception e) {
                System.out.println(e);
            }
    }
    //
    }

  8. #8
    Membre averti
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Par défaut
    Pour illustrer ma remarque,Voici un exemple simple il suffit de mettre le path d'un gros fichier (/cadnat/monfichier.txt) et le pb est le même.

    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
     
    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.*;
     
    //
    class InstPkg extends JPanel {
     
    //Variables
    JTextArea topTextArea ;
    ClientSsh ssh1 ;
    //
    public InstPkg() {
     
    		//Zone affichage
        topTextArea = new JTextArea();
    	topTextArea.setEditable(false);
        JScrollPane topScrollPane = new JScrollPane(topTextArea);
        Dimension preferredSize = new Dimension(1100, 400);
        topScrollPane.setPreferredSize(preferredSize);
    	   //Ajout au niveau du panel
    	this.add(topScrollPane) ;
    	//ClientSsh ssh1= new ClientSsh(topTextArea) ;
    	//ssh1.Lecture_Fic_Cnx("/cadnat/script/java/outils/ssh/cmd.txt") ;
    	Lecture_Fic_Cnx("/cadnat/monfichier.txt") ;
    	//topScrollPane.repaint() ;
     
    }
    //
    public void Lecture_Fic_Cnx(String ficparamcnx)
    {
    			String ligne;
    			String chaine="" ;
     
     
    	try {
    			InputStream ips=new FileInputStream(ficparamcnx); 
    			InputStreamReader ipsr=new InputStreamReader(ips);
    			BufferedReader br=new BufferedReader(ipsr);
    			while ((ligne=br.readLine())!=null){
                  topTextArea.append(ligne+"\n") ;
    			}
    			br.close(); 
     
     
    		}	
     
            catch(Exception er) {
    	System.out.println("Pb execution ") ;
    	er.printStackTrace() ;
     
    	System.out.println(er.getMessage()) ;
    			   }
     
    }
    //
     
     
    private static void showgui()
      {
      JFrame bt = new JFrame("Installation de Package Version 1.0 ") ;
      bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = bt.getContentPane() ;
      c.setLayout(new BorderLayout()) ;
      InstPkg  ma = new InstPkg () ;
      c.add(ma) ;
      bt.setSize(1200,800) ;
      bt.setVisible(true) ;
      }
     
    public static void main (String [] args)
        {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
       showgui() ;
    		    }
    		    });
        }
    }

  9. #9
    Membre chevronné Avatar de Ceddoc
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2009
    Messages
    493
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2009
    Messages : 493
    Par défaut
    Chez toi ça bugg ce code?

    Moi j'ai fait ce code avec un gros gros gros fichier txt et j'ai aucune erreur même en scrollant dans tous les sens.

    Citation Envoyé par kilou88 Voir le message
    Pour illustrer ma remarque,Voici un exemple simple il suffit de mettre le path d'un gros fichier (/cadnat/monfichier.txt) et le pb est le même.

    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
     
    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.*;
     
    //
    class InstPkg extends JPanel {
     
    //Variables
    JTextArea topTextArea ;
    ClientSsh ssh1 ;
    //
    public InstPkg() {
     
    		//Zone affichage
        topTextArea = new JTextArea();
    	topTextArea.setEditable(false);
        JScrollPane topScrollPane = new JScrollPane(topTextArea);
        Dimension preferredSize = new Dimension(1100, 400);
        topScrollPane.setPreferredSize(preferredSize);
    	   //Ajout au niveau du panel
    	this.add(topScrollPane) ;
    	//ClientSsh ssh1= new ClientSsh(topTextArea) ;
    	//ssh1.Lecture_Fic_Cnx("/cadnat/script/java/outils/ssh/cmd.txt") ;
    	Lecture_Fic_Cnx("/cadnat/monfichier.txt") ;
    	//topScrollPane.repaint() ;
     
    }
    //
    public void Lecture_Fic_Cnx(String ficparamcnx)
    {
    			String ligne;
    			String chaine="" ;
     
     
    	try {
    			InputStream ips=new FileInputStream(ficparamcnx); 
    			InputStreamReader ipsr=new InputStreamReader(ips);
    			BufferedReader br=new BufferedReader(ipsr);
    			while ((ligne=br.readLine())!=null){
                  topTextArea.append(ligne+"\n") ;
    			}
    			br.close(); 
     
     
    		}	
     
            catch(Exception er) {
    	System.out.println("Pb execution ") ;
    	er.printStackTrace() ;
     
    	System.out.println(er.getMessage()) ;
    			   }
     
    }
    //
     
     
    private static void showgui()
      {
      JFrame bt = new JFrame("Installation de Package Version 1.0 ") ;
      bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = bt.getContentPane() ;
      c.setLayout(new BorderLayout()) ;
      InstPkg  ma = new InstPkg () ;
      c.add(ma) ;
      bt.setSize(1200,800) ;
      bt.setVisible(true) ;
      }
     
    public static void main (String [] args)
        {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
       showgui() ;
    		    }
    		    });
        }
    }

  10. #10
    Membre averti
    Inscrit en
    Décembre 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 45
    Par défaut
    Effectivement, moi je passe par une machine de rebond pour lancer l'application, et je pense qu'il y a un pb au niveau des E/S graphique (pas assez de réseau) entre les deux machines. En exécutant l'application la ou elle est implantée cela fonctionne très bien.
    Merci beaucoup mon pb est résolu

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

Discussions similaires

  1. Traiter les flux de sortie
    Par soulhouf dans le forum Linux
    Réponses: 9
    Dernier message: 20/04/2006, 17h48
  2. [Java 1.5] Process : afficher le flux de sortie
    Par Zapan dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 11/01/2006, 10h34
  3. [MySQL] Flux de sortie : ob_start + header
    Par ToxiZz dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 13/12/2005, 23h56
  4. [JTextArea] affichage Map grande capacité
    Par tony_big_guy dans le forum Composants
    Réponses: 9
    Dernier message: 30/11/2005, 08h58
  5. Awk - changer le flux de sortie
    Par Longrais dans le forum Linux
    Réponses: 1
    Dernier message: 16/08/2005, 17h11

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