Bonjour,
Je dois ajouter un JScrollPane a un JPanel qui contient un tableau de JTextField mais je ne sais pas comment ajouter le JScrollPane si vous pouvez m'aider voila le code et Merci d'avance
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
 
import java.awt.*;
import java.io.*;
import javax.swing.*; // gerer l'interface graphique
import java.awt.event.*;// gérer les evenements
public class GestionTextField extends JFrame
{   //déclaration des variables        
    private JFrame       frameGestion;      
    private JPanel       panelGestion;
    private Container    cGestion;
    private JButton      btGestion; 
    private JLabel       lblGestion;
    private JTextField   txtGestion []= new JTextField[50];;
    private int          i=20, j=40, k=0; 
    private JScrollPane  jBar;  ///////////////////////////////
 
   /*<*><*><*><*><*><*> - Constructeur - <*><*><*><*><*><*><*/
    public GestionTextField() 
    {    //////////Instancier les variables ////////////
         frameGestion = new JFrame("Gestion des TextField");
         cGestion = frameGestion.getContentPane(); 
         panelGestion = new JPanel();
         btGestion = new JButton("Fermer");
         lblGestion=new JLabel("Les TextField :");
         jBar = new JScrollPane(); /////////////////////////////////////////////
 
         for(i=0;i<50;i++)
         {     txtGestion[i] = new JTextField();
               txtGestion[i].addActionListener(ajouterTxt); 
         }
        //////// Configurer les composantes /////////          
        cGestion.setLayout(null);
        frameGestion.setBounds(0, 0, 600, 600);
 
        lblGestion.setBounds(20,20,140,30);
        lblGestion.setFont(new Font("Dialog",Font.BOLD,18));
        frameGestion.add(lblGestion);        
 
        btGestion.setBounds(230,520,100,30);
        btGestion.setForeground(Color.black);
        frameGestion.add(btGestion); 
 
        panelGestion.setLayout(null);
        panelGestion.setBounds(0,70,600,400);
 
        jBar = new JScrollPane(panelGestion);/////////////////////////////////
 
        txtGestion[0].setBounds(20,0,500,30);
        panelGestion.add(txtGestion[0]);
 
        panelGestion.setPreferredSize(new Dimension(1000,1000));
        add(jBar);/////////////////////////////////////////////////////////////
 
        panelGestion.setVisible(true);
        frameGestion.getContentPane().add(panelGestion);
        frameGestion.setVisible(true); 
 
       ////La fermeture de la fenêtre 
       frameGestion.addWindowListener(new WindowListener() 
       {        public void windowOpened(WindowEvent e) {    }
                public void windowClosing(WindowEvent e) 
                {    frameGestion.setVisible(false);
                }
                public void windowClosed(WindowEvent e) { }
                public void windowIconified(WindowEvent e) { }
                public void windowDeiconified(WindowEvent e) { }
                public void windowActivated(WindowEvent e) { }
                public void windowDeactivated(WindowEvent e) {  }
        });
        ////ecouteur des évenements de boutons 
        btGestion.addActionListener(boutonAct); //pour fermer la fenetre 
   }
   /*<*><*><*>L'ecouteur sur le btGestion pr fermer la fenetre<*><*><*>*/
    private ActionListener boutonAct = new ActionListener() 
    {    public void actionPerformed(ActionEvent e) 
         {      if (e.getSource() == btGestion)  
                {  frameGestion.setVisible(false);
                }
          }
    };
    /*<*><*><* L'ecouteur sur le txtGestion pr ajouter TextField *<*><*>*/
    private ActionListener ajouterTxt = new ActionListener() 
    {    public void actionPerformed(ActionEvent e) 
         {      if (e.getSource() == txtGestion[k])  
                {  txtGestion[k+1].setBounds(20,j,500,30);
                   j=j+40;
                   txtGestion[k+1].setText(" ");
                   panelGestion.add(txtGestion[k+1]);
                   panelGestion.setVisible(true);
                   k=k+1; 
                }
          }
    }; 
    /*<*><*><*><*><*><*La fonction Main *><*><*><*><*><*><*>*/
    public static void main(String[] args) 
    {  GestionTextField essaye = new GestionTextField();     
    }
  }