// package fr.iutfbleau.papillon; import javax.swing.*; import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.Arrays; public class Main extends JFrame { private final List listRpl = new ArrayList<>(); public Main(){ super("Papillon"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Titre en haut JLabel titre = new JLabel("Rappel : Papillon", SwingConstants.CENTER); titre.setBorder(BorderFactory.createEmptyBorder(6,10,6,10)); // titre.setBackground(Color.CYAN); // ----- Grille centrale : boutons a gauche + liste scrollable a droite ----- JPanel body = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); Crud crud = new Crud(this); // Colonne 0 : boutons c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(4, 4, 4, 4); for(int i = 0; i< crud.size() ;i++){ c.gridx = 0; c.gridy = i; c.weighty = 0; body.add(crud.get(i), c); } // Colonne 1 : liste verticale de Rappel dans un JScrollPane JPanel liste = new JPanel(); liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS)); //Rappels GestionRappel g = new GestionRappel(); List listBd = new ArrayList<>(); try { listBd = g.lister(); } catch (Exception e) { e.printStackTrace(); // affiche l'erreur dans le terminal } for (int i = 0; i < listBd.size() ; i++) { PanelRappel r = new PanelRappel(listBd.get(i)); liste.add(r); listRpl.add(r); } JScrollPane scroll = new JScrollPane( liste, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); scroll.getVerticalScrollBar().setUnitIncrement(16); // molette fluide // place le scrollpane a droite, sur la hauteur des 2 lignes c.gridx = 1; c.gridy = 0; c.gridheight = 3; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(0, 0, 0, 0); c.weightx = 1.0; // prend la largeur dispo c.weighty = 1.0; // prend la hauteur dispo body.add(scroll, c); // barre en bas JLabel txtbarre = new JLabel("-", SwingConstants.CENTER); JPanel barre = new JPanel(); barre.add(txtbarre); barre.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); // barre.setBackground(Color.GRAY); // Conteneur racine JPanel root = new JPanel(new BorderLayout()); root.add(titre, BorderLayout.NORTH); root.add(body, BorderLayout.CENTER); root.add(barre, BorderLayout.SOUTH); setContentPane(root); // Taille fixe setSize(350, 250); setResizable(false); } public List getPanelRpl(){ return listRpl; } }