"lastModified")); thirdColumn.setPrefWidth(120); tableView.getColumns().addAll(firstColumn, secondColumn, thirdColumn); BorderPane borderPane = new BorderPane(); borderPane.setCenter(tree); borderPane.setRight(tableView); root.getChildren().addAll(tree, tableView); root.setPrefSize(800, 600); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); tree.expandedItemsProperty().addListener(new ChangeListener<ObservableList<TreeItem<File>>>() { @Override public void changed(ObservableValue<? extends ObservableList<TreeItem<File>>> observable, ObservableList<TreeItem<File>> oldValue, ObservableList<TreeItem<File>> newValue) { if (newValue != null) { for (TreeItem<File> item : newValue) { File file = item.getValue(); if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File f : files) { FileDetail detail = new FileDetail(f); data.add(detail); FileTreeItem childItem = new FileTreeItem(f); item.getChildren().add(childItem); } } } else { FileDetail detail = new FileDetail(file); data.add(detail); } } } } }); } public static class FileTreeItem extends TreeItem<File> { public FileTreeItem(File file) { super(file); setGraphic(new Label(file.getName())); if (file.isDirectory()) { setExpanded(true); } } } public static class FileDetail { private final StringProperty fileName = new SimpleStringProperty(); private final StringProperty type = new SimpleStringProperty(); private final StringProperty lastModified = new SimpleStringProperty(); public FileDetail(File file) { fileName.set(file.getName()); type.set(file.isDirectory() ? "目录" : "文件"); lastModified.set(file.lastModified() + ""); } public final StringProperty fileNameProperty() { return this.fileName; } public final String getFileName() { return this.fileNameProperty().get(); } public final void setFileName(final String fileName) { this.fileNameProperty().set(fileName); } public final StringProperty typeProperty() { return this.type; } public final String getType() { return this.typeProperty().get(); } public final void setType(final String type) { this.typeProperty().set(type); } public final StringProperty lastModifiedProperty() { return this.lastModified; } public final String getLastModified() { return this.lastModifiedProperty
- 粉丝: 4
- 资源: 992
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助