| A component that displays a set of hierarchical data as an outline.
Example:
Dialog treeFrame = new Dialog("Tree Test");
treeFrame.setBounds(25, 25, 400, 350);
final Label label = new Label("???????");
label.setBounds(225, 25, 150, 20);
Tree tree = new Tree();
tree.setBounds(10, 10, 200, 300);
Tree.Item root = tree.getRootItem();
root.setText("System Root");
root.setImage(SCORE_IMAGE);
tree.setRootItemVisible(false);
root.setExpanded(false);
Tree.Item readme = new Tree.Item("readme", FILE_IMAGE);
root.getChildren().add(readme);
Tree.Item bill = new Tree.Item("bill", FOLDER_IMAGE);
root.getChildren().add(bill);
Tree.Item startup = new Tree.Item("startup", FILE_IMAGE);
bill.getChildren().add(startup);
Tree.Item billFiles = new Tree.Item("files", FOLDER_IMAGE);
bill.getChildren().add(billFiles);
Tree.Item billFilesAddress = new Tree.Item("Address List", FILE_IMAGE);
billFiles.getChildren().add(billFilesAddress);
Tree.Item billFilesPhone = new Tree.Item("Phone List", FILE_IMAGE);
billFiles.getChildren().add(billFilesPhone);
bill.setExpanded(true);
billFiles.setExpanded(true);
Tree.Item billMusic = new Tree.Item("music", FOLDER_IMAGE);
bill.getChildren().add(billMusic);
Tree.Item billMusicSong1 = new Tree.Item("song1.mp3", FILE_IMAGE);
billMusic.getChildren().add(billMusicSong1);
Tree.Item billPic = new Tree.Item("pictures", FOLDER_IMAGE);
bill.getChildren().add(billPic);
Tree.Item billPicHome = new Tree.Item("home", FOLDER_IMAGE);
billPic.getChildren().add(billPicHome);
Tree.Item billPicS = new Tree.Item("s.jpg", PICTURE_IMAGE);
billPicHome.getChildren().add(billPicS);
Tree.Item billPicP = new Tree.Item("p.jpg", PICTURE_IMAGE);
billPicHome.getChildren().add(billPicP);
Tree.Item billPicM = new Tree.Item("m.jpg", PICTURE_IMAGE);
billPicHome.getChildren().add(billPicM);
Tree.Item jim = new Tree.Item("jim", FOLDER_IMAGE);
root.getChildren().add(jim);
Tree.Item jimStartup = new Tree.Item("startup", FILE_IMAGE);
jim.getChildren().add(jimStartup);
Tree.Item copyright = new Tree.Item("copyright", FILE_IMAGE);
root.getChildren().add(copyright);
tree.addPropertyChangeListener(Tree.Item.PROPERTY_SELECTED, new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
label.setText(((Tree.Item) ev.getSource()).getText());
}
});
treeFrame.getChildren().add(tree);
treeFrame.getChildren().add(label);
treeFrame.setVisible(true);
Keyboard Navigation:
KEY |
RESPONSE |
NOTE |
Space |
Fires PropertyChangeEvent( propertyName = Tree.Item.PROPERTY_CHECKED ) |
Only if the component has focus. |
author: Joshua J. Gertzen |