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
| public class Fenetre extends JFrame {
private JTree arbre, arbre2, arbre3;
private DefaultMutableTreeNode racine;
//On va créer deux modèles d'affichage
private DefaultTreeCellRenderer[] tCellRenderer = new DefaultTreeCellRenderer[3];
public Fenetre(){
this.setSize(600, 350);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Les arbres");
//On invoque la méthode de construction de l'arbre
initRenderer();
listRoot();
this.setVisible(true);
}
private void initRenderer(){
//Instanciation
this.tCellRenderer[0] = new DefaultTreeCellRenderer();
//Initialisation des images pour les actions fermer, ouvrir et pour les feuilles
this.tCellRenderer[0].setClosedIcon(new ImageIcon("img/ferme.jpg"));
this.tCellRenderer[0].setOpenIcon(new ImageIcon("img/ouvert.jpg"));
this.tCellRenderer[0].setLeafIcon(new ImageIcon("img/feuille.jpg"));
this.tCellRenderer[1] = new DefaultTreeCellRenderer();
this.tCellRenderer[1].setClosedIcon(null);
this.tCellRenderer[1].setOpenIcon(null);
this.tCellRenderer[1].setLeafIcon(null);
} |
Partager