Skip to content

Instantly share code, notes, and snippets.

@skht777
Created May 23, 2017 23:42
Show Gist options
  • Select an option

  • Save skht777/6c0ccf7c95baf303738d764fd6e659d7 to your computer and use it in GitHub Desktop.

Select an option

Save skht777/6c0ccf7c95baf303738d764fd6e659d7 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane prefHeight="500.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.112"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="fxtree.Main">
<left>
<fx:include source="tree.fxml"/>
</left>
</BorderPane>
package fxtree;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("Tree View Sample");
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TreeView fx:id="view" showRoot="false" xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="fxtree.TreeController"
prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<TreeItem value="/" expanded="true" fx:id="root" />
</TreeView>
package fxtree;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import java.net.URL;
import java.util.ResourceBundle;
/**
* @author skht
*/
public class TreeController implements Initializable {
@FXML
private TreeView view;
@FXML
private TreeItem<String> root;
@Override
public void initialize(URL location, ResourceBundle resources) {
TreeItem<String> mnt = new TreeItem<>("mnt");
mnt.setExpanded(true);
mnt.getChildren().add(new TreeItem<>("★strage-data"));
TreeItem<String> var = new TreeItem<>("var");
var.getChildren().add(new TreeItem<>("★sel-decode"));
var.setExpanded(true);
root.getChildren().addAll(mnt, var);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment