JTabbedPane: Ajouter ‘JTextField’ à l’intérrieur d’une onglet

Author:

{filelink=900}

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

public class ExempleTabbedPane
{
  static void ajouterLOnglet(JTabbedPane onglet, String texte) {
    JLabel label = new JLabel(texte);
    JButton bouton = new JButton(texte);
    JPanel panel = new JPanel();
    panel.add(label);
    panel.add(bouton);
    onglet.addTab(texte, panel);
    onglet.setTabComponentAt(onglet.getTabCount() - 1, new JTextField(texte));
  }

  public static void main(String args[]) {
    JFrame frame = new JFrame("Exemple TabbedPane");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTabbedPane tabbedPane = new JTabbedPane();
    ajouterLOnglet(tabbedPane, "Un");
    ajouterLOnglet(tabbedPane, "Deux");
    ajouterLOnglet(tabbedPane, "Trois");
    ajouterLOnglet(tabbedPane, "Quatre");
    ajouterLOnglet(tabbedPane, "Cinq");
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(600, 200);
    frame.setVisible(true);

  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *