To reproduce:
1. Expand all nodes.
2. Push Ctrl + A.
3. Click button.
Focused item is "Item 2 3"
But it's hidden from viewable area.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class TreeViewFocus extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
HBox root = new HBox(10d);
final TreeView<String> treeView = new TreeView<>();
treeView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
TreeItem rootItem = new TreeItem("ROOT");
treeView.setRoot(rootItem);
for (int i = 0; i < 3; i++) {
TreeItem parent = new TreeItem("Item " + i);
rootItem.getChildren().add(parent);
for (int j = 0; j < 4; j++) {
TreeItem childItem = new TreeItem("Item " + i + " " + j);
parent.getChildren().add(childItem);
}
}
root.getChildren().add(treeView);
Label lblFocusedItemHeader = new Label("Focused item: ");
final Label lblFocusedItem = new Label();
HBox hbFocusedItem = new HBox();
Button btnGetSelectedItem = new Button("Show focused item");
btnGetSelectedItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
lblFocusedItem.setText(treeView.getFocusModel().getFocusedItem().getValue());
}
});
hbFocusedItem.getChildren().addAll(btnGetSelectedItem, lblFocusedItemHeader, lblFocusedItem);
root.getChildren().add(hbFocusedItem);
Scene scene = new Scene(root, 600, 300);
stage.setScene(scene);
stage.show();
}
}
1. Expand all nodes.
2. Push Ctrl + A.
3. Click button.
Focused item is "Item 2 3"
But it's hidden from viewable area.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class TreeViewFocus extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
HBox root = new HBox(10d);
final TreeView<String> treeView = new TreeView<>();
treeView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
TreeItem rootItem = new TreeItem("ROOT");
treeView.setRoot(rootItem);
for (int i = 0; i < 3; i++) {
TreeItem parent = new TreeItem("Item " + i);
rootItem.getChildren().add(parent);
for (int j = 0; j < 4; j++) {
TreeItem childItem = new TreeItem("Item " + i + " " + j);
parent.getChildren().add(childItem);
}
}
root.getChildren().add(treeView);
Label lblFocusedItemHeader = new Label("Focused item: ");
final Label lblFocusedItem = new Label();
HBox hbFocusedItem = new HBox();
Button btnGetSelectedItem = new Button("Show focused item");
btnGetSelectedItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
lblFocusedItem.setText(treeView.getFocusModel().getFocusedItem().getValue());
}
});
hbFocusedItem.getChildren().addAll(btnGetSelectedItem, lblFocusedItemHeader, lblFocusedItem);
root.getChildren().add(hbFocusedItem);
Scene scene = new Scene(root, 600, 300);
stage.setScene(scene);
stage.show();
}
}