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
|
class dlgMessageSelector_Renderer extends JPanel implements TreeCellRenderer {
...
/**
* Un label qui se comportera comme un noeud dans un arbre classique
*/
DefaultTreeCellRenderer labLabel = new DefaultTreeCellRenderer();
/**
* Le label avec l'info supplémentaire, qui apparaît ou pas suivant les cas.
*/
JLabel labAutre = new JLabel("Autre info");
LayoutManager layout;
public dlgMessageSelector_Renderer(Font plain) {
// Initialisation fonctionnelle
...
//Initialisation graphique du panel
layout = new BoxLayout(this, SwingConstants.VERTICAL);
this.setLayout(layout);
// Initialisation graphique du labLabel
labLabel.setClosedIcon(null);
labLabel.setOpenIcon(null);
labLabel.setLeafIcon(null);
this.add(labLabel);
// Initialisation graphique des autres infos
this.add(labAutre);
}
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
int row, boolean hasFocus) {
labLabel.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
String d = node.getUserObject().toString();
// 1) Les couleurs en fonction de la nature du noeud (titre, new, normal)
labLabel.setFont(plain);
if (node.getUserObject() instanceof MessageNode) {
...
}
// 2) Les autres info du panneau
labAutre.setVisible(sel);
// 3) La hauteur du panneau
this.setMinimumSize(layout.minimumLayoutSize(this));
return this;
}
} |
Partager