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
| arbre.addTreeSelectionListener(new TreeSelectionListener(){
public void valueChanged(TreeSelectionEvent event) {
if(arbre.getLastSelectedPathComponent() != null){
File file = new File(getAbsolutePath(event.getPath()));
try {
PanneauImg = new PanneauImage(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private String getAbsolutePath(TreePath treePath){
String str = "";
//On balaie le contenu de l'objet TreePath
for(Object name : treePath.getPath()){
//Si l'objet a un nom, on l'ajoute au chemin
if(name.toString() != null)
str += name.toString();
}
return str;
}
}); |