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
| import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
public class Facture extends JPanel{
private static final long serialVersionUID = 1L;
private ArrayList<Categorie> listCategorie = new ArrayList<Categorie>();
public void add(Categorie categorie){
listCategorie.add(categorie);
}
public void getContent(){
setLayout(new BorderLayout());
//Panneau externe avec bordure noire
JPanel panneauExterne = new JPanel();
panneauExterne.setBorder(new CompoundBorder(new MatteBorder(3,3,3,3, Color.BLACK),new EmptyBorder(5,5,5,5)) );
panneauExterne.setLayout(new GridBagLayout());
//Entête crée à partir d'une JTable quelconque
JTable tableauPourEntete = new JTable(new ModelTableau(new Categorie("Fictive")));
GridBagConstraints contrainte = new GridBagConstraints();
contrainte.weightx = contrainte.weighty = 1;
contrainte.fill = GridBagConstraints.HORIZONTAL;
panneauExterne.add(tableauPourEntete.getTableHeader(), contrainte);
//Le corp de la facture
JPanel panneauInterne = new JPanel();
panneauInterne.setLayout(new GridBagLayout());
contrainte.gridx = 0;
for (Categorie categorie : listCategorie) {
if (!categorie.getListProduit().isEmpty()){
//Ajoute l'étiquette de la catégorie
JLabel etiquette = new JLabel(categorie.getNom()+ " (" + categorie.getListProduit().size() + ")");
contrainte.gridy++;
panneauInterne.add(etiquette, contrainte);
//Ajoute le tableau de données
JTable tableau = new JTable(new ModelTableau(categorie));
tableau.setColumnModel(tableauPourEntete.getColumnModel());
contrainte.gridy++;
panneauInterne.add(tableau, contrainte);
}
}
//Place le panneau interne dans une zone scrollable
contrainte.gridy = 1;
JScrollPane sPan = new JScrollPane(panneauInterne);
sPan.setBorder(new EmptyBorder(0,0,0,0));
panneauExterne.add(sPan, contrainte);
add(panneauExterne, BorderLayout.CENTER);
}
} |
Partager