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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
//JPanel pour les ateliers
public class pnlBordureAteliers extends JPanel implements MouseListener {
private static final long serialVersionUID = 20190125;
public pnlBordureAteliers() {
private Object[][] listeAteliersConvertie = {
{"Cysboy", new JButton("6boy"), new Double(1.80), new ImageIcon("Images/Maths/perles.jpg")},
{"BZHHydde", new JButton("BZH"), new Double(1.78), new ImageIcon("Images/Maths/perles.jpg")},
{"IamBow", new JButton("BoW"), new Double(1.90), new ImageIcon("Images/Maths/perles.jpg")},
{"FunMan", new JButton("Year"), new Double(1.85), new ImageIcon("Images/Maths/perles.jpg")}
};
public void afficherTableauListeAteliers(ArrayList<Atelier> listeaAfficher, int selectionLigne) {
String[] titresColonnes = {"Nom", "Catégorie", "Image", "ok?"};
tableauAteliers = new ModeleTableauListeAteliers(listeAteliersConvertie, titresColonnes);
//Mettre ce modèle dans un JTable
tableauDonneesAteliers = new JTable(tableauAteliers);
tableauDonneesAteliers.getColumnModel().getColumn(3).setCellRenderer(new ImageCellRenderer());
//Mettre le JTable dans un JScrollPane indispensable pour avoir les titres de colonnes
tableauAteliersComplet = new JScrollPane(tableauDonneesAteliers);
//Ajouter le nouveau tableau dans le JPanel
grillePanneauAteliers.gridx = 1;
grillePanneauAteliers.gridy = 0;
//Taille de la case
grillePanneauAteliers.gridheight = 2;
//Marges (haut, gauche, bas, droite)
grillePanneauAteliers.insets = new Insets(0,100,0,0);
tableauAteliersComplet.setPreferredSize(new Dimension(500,150));
//Ajouter le tableau
this.add(tableauAteliersComplet, grillePanneauAteliers);
}
public class ImageCell implements TableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
// TODO Auto-generated method stub
JLabel label = new JLabel();
label.setText((String)listeAteliersConvertie[row][1]);
label.setIcon((ImageIcon)listeAteliersConvertie[row][3]);
return (Component) label;
}
}
public class ImageCellRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
JLabel label = (JLabel)component;
String cheminImage = String.valueOf(value);
ImageIcon icon = new ImageIcon(cheminImage);
if ( icon.getImageLoadStatus()==java.awt.MediaTracker.COMPLETE ) {
label.setIcon(icon);
table.setRowHeight(row, icon.getIconHeight());
}
else {
label.setIcon(null);
table.setRowHeight(row, table.getRowHeight());
}
label.setText(""); // on efface le texte
return component;
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
//Déterminer quelle catégorie est sélectionnée
selection = PanneauGestionAteliers.tableauDonneesCategories.getSelectedRow();
//Appeler la méthode d'affichage du tableau de la catégorie
afficherTableauListeAteliers(listeAteliersUneCategorie, selection);
} |
Partager