Problème de ScrollBar

Al3x38 Messages postés 6 Date d'inscription mercredi 17 mai 2006 Statut Membre Dernière intervention 26 avril 2008 - 26 avril 2008 à 11:42
Al3x38 Messages postés 6 Date d'inscription mercredi 17 mai 2006 Statut Membre Dernière intervention 26 avril 2008 - 26 avril 2008 à 17:50
Bonjour tout le monde,

Voila j'ai un petit soucy pour mon projet d'info ! je n'arrive pas à mettre une scrollbar dans un jtextarea. Bon pour indication, je ne suis pas débutant en programmation normal (php, html, java etc... ). Par contre, en Java graphique, je suis une vraie B.I.T.E :D !
Le probleme se situe au niveau de mon Jtextarea reponse, qui affiche les résultats d'une BDD donc j'ai besoin d'une scroll bar, j'ai essayé les solutions deja trouvé sur le forum là mais sa ne marchait pas :S.
En gros, je cherche juste la mini ligne de code qui résoudrait mon probleme :O ( PS : si possible, ma scroll bar dans les 2 cas, horizontale et verticale ;)

Bonne journée et merci d'avance,

Alex

Voici mon code :

/*
 * Produit.java
 *
 * Created on 7 avril 2008, 22:55
 */


package fr.insa.alex;


import java.awt.*;
import javax.swing.BorderFactory;


/**
 *
 * @author  Alexxx
 */
public class Produit extends javax.swing.JFrame {
   
    /** Creates new form Produit */
    public Produit() {
        initComponents();
    }
   
                         
    private void initComponents() {


        Titre = new javax.swing.JLabel();
        reponse = new javax.swing.JTextArea();
        menu = new javax.swing.JButton();
        affiche = new javax.swing.JButton();
       


        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Projet INFO STH 2");
        setSize(550,350);
       
        Container contenu = getContentPane() ;
        contenu.setLayout(null) ;


        Titre.setFont(new java.awt.Font("Tahoma", 0, 18));
        Titre.setText("Liste des produits ");
        Titre.setBounds(200,30,200,22);


        reponse.setColumns(20);
        reponse.setRows(5);
        reponse.setBorder(BorderFactory.createLineBorder(Color.black));
        reponse.setBounds(40,85,450,180);
      


        menu.setText("Retourner au menu");
        menu.setFont(new java.awt.Font("Tahoma", 0, 11));
        menu.setBounds(80,280,160,23);
        menu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuActionPerformed(evt);
            }
        });


        affiche.setText("Afficher les produits existants");
        affiche.setFont(new java.awt.Font("Tahoma", 0, 11));
        affiche.setBounds(280,280,200,23);
        affiche.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                afficheActionPerformed(evt);
            }
        });
       
        contenu.add(menu);
        contenu.add(Titre);
        contenu.add(affiche);
        contenu.add(reponse);
        contenu.add(menu);
        contenu.add(menu);
               
       


       
    }           


    private void menuActionPerformed(java.awt.event.ActionEvent evt) {                                    
        setVisible(false);
        Menu men =new Menu();
        men.setLocationRelativeTo(null);
        men.setVisible(true);
    }                                   


    private void afficheActionPerformed(java.awt.event.ActionEvent evt) {                                       
        String z = Fonction_bdd.afficheTousLesProduits();
        reponse.setText(z);
    }                                      
   
    /**
     * @param args the command line arguments
     /
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Produit_old().setVisible(true);
            }
        });
    }*/
   
    // Variables declaration - do not modify                    
    private javax.swing.JLabel Titre;
    private javax.swing.JButton affiche;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton menu;
    private javax.swing.JTextArea reponse;
    // End of variables declaration                  
   
}

2 réponses

cs_Chatbour Messages postés 764 Date d'inscription jeudi 27 juillet 2006 Statut Membre Dernière intervention 6 septembre 2010 19
26 avril 2008 à 16:06
Salut,

voilà un petit exemple :

import javax.swing.*;
import java.awt.*;

class Tester extends JFrame {
    public Tester() {
        JTextArea txtArea = new JTextArea();
        JScrollPane scroll = new JScrollPane(txtArea);
       
        JPanel pan = new JPanel();
        pan.add(scroll);
        this.getContentPane().add(scroll, BorderLayout.CENTER);
       
        this.setSize(300, 200);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
   
    public static void main(String[] args) {
        new Tester();
       
    }
}
0
Al3x38 Messages postés 6 Date d'inscription mercredi 17 mai 2006 Statut Membre Dernière intervention 26 avril 2008
26 avril 2008 à 17:50
Euh ouai, j'ai déjà un exemple comme ca, mais bon moi j'arrive pas à le refaire par rapport à mon programme. C'est peut etre car je n'ai pas de JPannel et juste un JFrame.
0
Rejoignez-nous