Voici le résultat
Voici le code de test.java
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class test extends JFrame{
private JLabel label;
private JPanel basePanel;
public test(){
this.setTitle("Ma fenêtre");
this.setSize(200,200);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
// C'est ici que la magie opère, on créé autant de JLabel qu'il y a d'itérations
basePanel = new JPanel();
for(int i=0; i<5; i++) {
label = new JLabel();
label.setText("Itération numéro "+i);
basePanel.add(label);
}
// Fin de la magie
this.setContentPane(basePanel);
this.setVisible(true);
}
public static void main (String[] args) {
test maFenetre = new test();
}
}