Affichage d'un JPanel dans JScrollPane: est-ce possible ?
Goahould_nt
Messages postés17Date d'inscriptionvendredi 21 avril 2023StatutMembreDernière intervention25 mai 2023
-
Modifié le 18 mai 2023 à 18:30
Goahould_nt
Messages postés17Date d'inscriptionvendredi 21 avril 2023StatutMembreDernière intervention25 mai 2023
-
19 mai 2023 à 00:59
J'ai le code suivant :
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SGUI extends JFrame implements ActionListener {
public JPanel jp;
public JScrollPane jsp;
public JTextField jtf1, jtf2;
public JLabel jl1, jl2;
public JButton ok;
public SGUI(String titre) {
jsp = new JScrollPane();
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jp = new JPanel();
jp.setVisible(true);
jp.setBackground(Color.BLUE);
jtf1 = new JTextField("Ecrivez le texte a placer",50);
jtf2 = new JTextField("Ecrivez le texte a placer",50);
jtf2.setVisible(false);
jl1 = new JLabel("Colonne 1");
jl2 = new JLabel("Colonne 2");
jl2.setVisible(false);
ok = new JButton("OK");
ok.addActionListener(this);
jp.add(jl1);
jp.add(jtf1);
jp.add(jl2);
jp.add(jtf2);
jp.add(ok);
jsp.add(jp);
this.add(jsp);
this.setBounds(10, 20, 300, 400);
}
public void actionPerformed(ActionEvent ev) {
Object obj = ev.getSource();
if (obj == ok) {
jtf2.setVisible(true);
jl2.setVisible(true);
}
}
public static void main (String args[]) {
SGUI frm = new SGUI("Test d'affichage");
frm.setVisible(true);
}
}
et le le JPanel en bleu n'apparaît pas. Savez-vous pourquoi ?
A voir également:
Affichage d'un JPanel dans JScrollPane: est-ce possible ?