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 :

Comment faire un JTextArea


Sujet :

Java

  1. #1
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut Comment faire un JTextArea
    Bonjour
    Je cherche a faire un JTextArea pour afficher du texte venant de ma console.
    Par contre pas moyen de trouver un tuto bien expliqué donc je galere un peu.Si quelqu'un peu m'orienter vers un bon tuto ou m'aider a faire mon JTextFrame.
    Merci d'avance

  2. #2
    Membre expérimenté Avatar de Amine_sas
    Profil pro
    Étudiant
    Inscrit en
    Juin 2005
    Messages
    245
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2005
    Messages : 245
    Par défaut
    Salut,
    Voici un lien vers le tutoriel de Sun

  3. #3
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    Bonjour
    Voila j'ai créé mon JTextArea et mon texte s'affiche dans ma console.
    Comment faire maintenant pour qu'il s'affiche dans mon JTextArea?
    Comment fonctionne le ...setText(...)?

  4. #4
    Membre Expert Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    JTextArea text = new JTextArea ();
    text.setText("Le texte à afficher");

  5. #5
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    Voila le programme suivant va lire le texte dans un fichier .txt
    J'aimerai ensuite l'afficher dans mon JtextArea mais il m'affiche des erreurs
    Voici ce que j'ai fait:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    public void LireFaits() throws FileNotFoundException, IOException {
            System.out.println("La liste des faits est la suivante :");
            File f = new File("c:/faits.txt");
            FileReader lecteur = new FileReader(f);
        int car;
        while((car = lecteur.read()) != -1){
        System.out.print ((char)car);
     
    JTextArea1 text = new JTextArea1 ();
    text.setText("char");
               }

  6. #6
    Membre Expert Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Par défaut
    Il y a plusieurs problème dans ton code :
    - déja si ton fichier texte contient des caractères il est plus facile de le lire ligne par ligne en utilisant un BufferedReader
    - ensuite à chaque iteration de ta boucle tu écrase ce qu'il y a dans ton JTextArea
    Ca pourrais donner un truc du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    public void LireFaits() throws FileNotFoundException, IOException {
            System.out.println("La liste des faits est la suivante :");
            File f = new File("c:/faits.txt");
            FileReader filelecteur = new FileReader(f);
            BufferedReader lecteur = new BufferedReader (filelecteur );
        String ligne;
        JTextArea1 text = new JTextArea1 ();
        String laChaine = "";
        while((ligne= lecteur.read()) != null){
        laChaine += ligne; 
               }
        text.setText(laChaine );
    PS : par convention les noms des méthodes commence par une minuscule

  7. #7
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    Le compilateur m'indique une erreur au niveau du while comme quoi il y aurait des types incompatibles (int et string)

    voici l'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Compiling 2 source files to C:\Documents and Settings\Administrateur\TP\build\classes
    C:\Documents and Settings\Administrateur\TP\src\tp\TPApp.java:67: incompatible types
    found   : int
    required: java.lang.String
        while((ligne= lecteur.read()) != null){
    1 error
    BUILD FAILED (total time: 0 seconds)
    )

  8. #8
    Membre Expert Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Par défaut
    C'est une erreur de ma part il faut utiliser la méthode readLine et non read.

  9. #9
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    Ok merci
    Maintenant mon programme compile et lorsque que j'appuie sur mon bouton pour executer l'action j'ai une longue liste d'erreurs qui apparait.
    ça donne sa:
    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
     
    init:
    deps-jar:
    compile:
    run:
    La liste des faits est la suivante :
    Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.InvocationTargetException
            at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAction.java:859)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:665)
            at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
            at java.awt.Component.processMouseEvent(Component.java:6041)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
            at java.awt.Component.processEvent(Component.java:5806)
            at java.awt.Container.processEvent(Container.java:2058)
            at java.awt.Component.dispatchEventImpl(Component.java:4413)
            at java.awt.Container.dispatchEventImpl(Container.java:2116)
            at java.awt.Component.dispatchEvent(Component.java:4243)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
            at java.awt.Container.dispatchEventImpl(Container.java:2102)
            at java.awt.Window.dispatchEventImpl(Window.java:2440)
            at java.awt.Component.dispatchEvent(Component.java:4243)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
            ... 27 more
    Caused by: java.lang.UnsupportedOperationException: Not yet implemented
            at tp.JTextArea1.setText(JTextArea1.java:18)
            at tp.TPApp.LireFaits(TPApp.java:62)
            ... 32 more
    Il ne me manquerai pas une librairy?

  10. #10
    Membre Expert Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Par défaut
    Il y a une erreur dans ton code que j'ai repris dans mon copier coller c'est JTextArea et non JTextArea1

  11. #11
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    oui mais moi je veux l'afficher dans ma fenetre qui se nomme JTexteArea1.
    Si je mets JTexteArea je n'ai pas de probleme de compil mais bon programme se bloque.
    Le compilateur affiche "La liste des faits est la suivante :" puis il attends

  12. #12
    Membre Expert Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Par défaut
    Je ne comprend plus grand chose de ce que tu dis. Poste ton code je pense que ça sera plus clair pour tout le monde.

  13. #13
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    Voila je vais essayer d'etre un peu plus clair.
    J'ai revu mon programme
    L'action du bouton LireFaits est sensé lire le contenu de mon fichier texte "Faits " et de l'afficher dans mon JTextArea1.
    Je n'ai aucune erreur a a conpilation et pourtant lorsque je clique sur mon bouton rien e se passe. C'est un bout de programme que j'ai récupéré sur le net car je ne m'en sorté pas don il doit etre oopérationnel.Mais avec moi sa ne fonctionne pas

    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
     
            @Action
     
        @SuppressWarnings("empty-statement")
        public void resultat(){                                      
            int i = 0;
    	char toto;
    	jTextArea1.setText("Nouvelle base des faits:\n{" +tabresultat[i]);
    	i = i + 1;
    	while (tabresultat[i] != 0)
    		{
                    jTextArea1.append("," + tabresultat[i]);
    		i = i + 1;
    		}
    	jTextArea1.append("}");
          }
    aidez moi svp, merci beaucoup

  14. #14
    Membre expérimenté Avatar de Amine_sas
    Profil pro
    Étudiant
    Inscrit en
    Juin 2005
    Messages
    245
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2005
    Messages : 245
    Par défaut
    Salut,
    Comment as tu créé le bouton et l'action associée. Merci de poster le code correspondant (inutile de poster 400 lignes de code ).

  15. #15
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    j'ai fait mon interface graphique a partir de l'éditeur graphique de netbeans

  16. #16
    Membre expérimenté Avatar de Amine_sas
    Profil pro
    Étudiant
    Inscrit en
    Juin 2005
    Messages
    245
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2005
    Messages : 245
    Par défaut
    Salut,
    Citation Envoyé par babylone_59 Voir le message
    j'ai fait mon interface graphique a partir de l'éditeur graphique de netbeans
    mais il existe certainement un code source.

  17. #17
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    oui j'ai le code pour l'interface que voici:

    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
     
    package tp;
     
    import org.jdesktop.application.Action;
    import org.jdesktop.application.ResourceMap;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import org.jdesktop.application.TaskMonitor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import javax.swing.Timer;
    import javax.swing.Icon;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
     
    /**
     * The application's main frame.
     */
    public class TPView extends FrameView {
     
     
        @SuppressWarnings("empty-statement")
        public TPView(SingleFrameApplication app) {
            super(app);
     
            initComponents();
     
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
                }
            });
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            }
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
                }
            });
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(false);
     
            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setVisible(false);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
        }
     
        @Action
        public void showAboutBox() {
            if (aboutBox == null) {
                JFrame mainFrame = TPApp.getApplication().getMainFrame();
                aboutBox = new TPAboutBox(mainFrame);
                aboutBox.setLocationRelativeTo(mainFrame);
            }
            TPApp.getApplication().show(aboutBox);
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            mainPanel = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jButton4 = new javax.swing.JButton();
            jButton5 = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            statusPanel = new javax.swing.JPanel();
            javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
            statusMessageLabel = new javax.swing.JLabel();
            statusAnimationLabel = new javax.swing.JLabel();
            progressBar = new javax.swing.JProgressBar();
     
            mainPanel.setName("mainPanel"); // NOI18N
     
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(tp.TPApp.class).getContext().getResourceMap(TPView.class);
            jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N
     
            javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(tp.TPApp.class).getContext().getActionMap(TPView.class, this);
            jButton1.setAction(actionMap.get("LireFaits")); // NOI18N
            jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
            jButton1.setName("jButton1"); // NOI18N
     
            jButton2.setAction(actionMap.get("LireRegles")); // NOI18N
            jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
            jButton2.setName("jButton2"); // NOI18N
     
            jButton3.setAction(actionMap.get("ChainageAvant")); // NOI18N
            jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
            jButton3.setName("jButton3"); // NOI18N
     
            jButton4.setAction(actionMap.get("ChainageArriere")); // NOI18N
            jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
            jButton4.setName("jButton4"); // NOI18N
     
            jButton5.setAction(actionMap.get("quit")); // NOI18N
            jButton5.setName("jButton5"); // NOI18N
     
            jScrollPane1.setName("jScrollPane1"); // NOI18N
     
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jTextArea1.setName("jTextArea1"); // NOI18N
            jScrollPane1.setViewportView(jTextArea1);
     
            javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
            mainPanel.setLayout(mainPanelLayout);
            mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(144, 144, 144))
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton4)
                            .addContainerGap())
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                            .addComponent(jButton5)
                            .addContainerGap())))
            );
            mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                    .addGap(11, 11, 11)
                    .addComponent(jButton5)
                    .addContainerGap())
            );
     
            statusPanel.setName("statusPanel"); // NOI18N
     
            statusMessageLabel.setName("statusMessageLabel"); // NOI18N
     
            statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
     
            progressBar.setName("progressBar"); // NOI18N
     
            javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
            statusPanel.setLayout(statusPanelLayout);
            statusPanelLayout.setHorizontalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(statusMessageLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 246, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(statusAnimationLabel)
                    .addContainerGap())
            );
            statusPanelLayout.setVerticalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(statusMessageLabel)
                        .addComponent(statusAnimationLabel)
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(3, 3, 3))
            );
     
            setComponent(mainPanel);
            setStatusBar(statusPanel);
        }// </editor-fold>                        
     
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JButton jButton4;
        private javax.swing.JButton jButton5;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JPanel mainPanel;
        private javax.swing.JProgressBar progressBar;
        private javax.swing.JLabel statusAnimationLabel;
        private javax.swing.JLabel statusMessageLabel;
        private javax.swing.JPanel statusPanel;
        // End of variables declaration                   
     
        private final Timer messageTimer;
        private final Timer busyIconTimer;
        private final Icon idleIcon;
        private final Icon[] busyIcons = new Icon[15];
        private int busyIconIndex = 0;
     
        private JDialog aboutBox;
    }

    et la source permettant d'attibuer les actions des boutons


    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
     
    package tp;
     
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import javax.swing.JTextArea;
    import org.jdesktop.application.Application;
    import org.jdesktop.application.SingleFrameApplication;
     
    /**
     * The main class of the application.
     */
    @SuppressWarnings("empty-statement")
    public class TPApp extends SingleFrameApplication {
     
        /**
         * At startup create and show the main frame of the application.
         */
        @Override protected void startup() {
            show(new TPView(this));
        }
     
     
        /**
         * This method is to initialize the specified window by injecting resources.
         * Windows shown in our application come fully initialized from the GUI
         * builder, so this additional configuration is not needed.
         */
        @Override protected void configureWindow(java.awt.Window root) {
        }
     
        /**
         * A convenient static getter for the application instance.
         * @return the instance of TPApp
         */
        public static TPApp getApplication() {
            return Application.getInstance(TPApp.class);
        }
     
        /**
         * Main method launching the application.
         */
        public static void main(String[] args) throws  IOException {
            launch(TPApp.class, args);
     
        }
     
        @org.jdesktop.application.Action
     
    public void LireFaits() throws FileNotFoundException, IOException {
              try
    { FileInputStream fis = new FileInputStream("c:/faits.txt");
    // Créer un flux d’entrée avec comme paramètre le nom
    //du fichier à ouvrir
       int n;
       while ((n = fis.available())> 0) // tant qu’il y a des données dans le flux…
       { byte[] b = new byte[n]; // récupérer le byte à l’endroit n et le stocker dans un tableau de bytes
         int result = fis.read(b); // lire ce tableau de byte à l’endroit
        //désiré
          if (result== -1) break; // si le
        //byte est -1, c’est que le flux est arrivé à sa fin (par définition)
          String s = new String(b);
        // assembler les bytes pour former une chaîne
          jTextArea1.setText(s); //
        //insérer cette chaîne dans notre composant de texte
       }
    } catch (Exception err) {;}
     
        }
     
     
     
        @org.jdesktop.application.Action
        public void LireRegles() throws FileNotFoundException, IOException {
            System.out.println("La liste des régles est la suivante :");   
            File f = new File("c:/Regles.txt");
            FileReader lecteur = new FileReader(f);
        int car;
        while((car = lecteur.read()) != -1){
        System.out.print ((char)car);
     
            }
        }
     
        @org.jdesktop.application.Action
        public void ChainageAvant() {
            System.out.println("ici il y aura le chainage avant");
     
        }
     
        @org.jdesktop.application.Action
        public void ChainageArriere() {
            System.out.println("Chainage Arriére");        
     
        }
    }
    Mon probleme se trouve dans le code que j'ai posté précedement.
    Je pense que mon texte est lu mais celui ci ne s'affiche dans dans mon JTaextArea1.
    Merci pour votre aide

  18. #18
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    bonjour
    Je n'en ai aucune idée, j'arrive pas a trouver ce qui se passe.
    En fait dans mon programme ,le probleme que j'ai c'est que mon programme execute toujours l'exeption et ne prends donc pas en compte l'algo avant lui!
    Je ne vois pas pourquoi
    Si quelqu'un peut m'aider?
    merci

  19. #19
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2006
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2006
    Messages : 77
    Par défaut
    Comment écrire simplement dans un jtexteArea?
    En utilisant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    jTextArea1.setText("bonjour");
    Je devrai voir apparaitre quelque chose?

  20. #20
    Membre expérimenté Avatar de Amine_sas
    Profil pro
    Étudiant
    Inscrit en
    Juin 2005
    Messages
    245
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2005
    Messages : 245
    Par défaut
    Salut,
    Citation Envoyé par babylone_59 Voir le message
    Comment écrire simplement dans un jtexteArea?
    En utilisant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    jTextArea1.setText("bonjour");
    Je devrai voir apparaitre quelque chose?
    Oui. Et pour ajouter un nouveau texte sans que l'ancien ne soit écrasé on utilise:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    textArea.append(newText);

Discussions similaires

  1. Réponses: 10
    Dernier message: 09/02/2011, 11h31
  2. Comment faire afficher le nom de fichier sur JTextArea?
    Par stpaul04 dans le forum Débuter
    Réponses: 1
    Dernier message: 26/01/2011, 18h14
  3. lire JTextArea / comment faire?
    Par soumamort dans le forum Applets
    Réponses: 1
    Dernier message: 02/05/2008, 15h02
  4. Comment faire pour mettre l'ecran en veille ?
    Par March' dans le forum MFC
    Réponses: 6
    Dernier message: 29/08/2002, 14h25
  5. Comment faire pour créer un bitmap
    Par GliGli dans le forum C++Builder
    Réponses: 2
    Dernier message: 24/04/2002, 15h41

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