package graphics.api.control; import javafx.event.EventHandler; import javafx.application.Application; import javafx.beans.property.IntegerProperty; import javafx.scene.control.*; import javafx.scene.text.*; import javafx.stage.*; import javafx.scene.*; import javafx.scene.input.*; import javafx.scene.layout.*; import javafx.collections.ObservableList; public class ListViewFocusShift extends Application { public static void main(String[] args) { ListViewFocusShift.launch(args); } ObservableList listItems = javafx.collections.FXCollections.observableArrayList(); ListView listView = new ListView(); CheckBox parentBox = new CheckBox(); CheckBox blocksMouseBox = new CheckBox(); Scene scene; Stage appFrame; IntegerProperty translateXVal = new IntegerProperty(0); IntegerProperty translateYVal = new IntegerProperty(0); int w = 500, h = 500; @Override public void start(Stage appFrame) throws Exception { appFrame = new Stage(); appFrame.setTitle("ListViewTest 4"); scene = new Scene(new Group(), w, h); float buttonH = 20;//TODO: Fix me getButtonHeight(6, getH()); float HalfOfButtonH = buttonH / 2; for (int i = 1; i <= 10; i++) { TextBox textbox = new TextBox(); textbox.setText("Click Me " + i); textbox.setFont(new Font(16)); listItems.add(textbox); } listView.getItems().clear(); listView.getItems().addAll(listItems); listView.getTransforms().clear(); listView.translateXProperty().bind(translateXVal); listView.translateYProperty().bind(translateYVal); listView.setPrefWidth(5 * w / 12); listView.setPrefHeight(5 * buttonH); listView.setMaxWidth(5 * w / 12); listView.setMaxHeight(5 * buttonH); listView.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent e) { if (e.getCode().equals(KeyCode.DIGIT6)) { translateYVal.set(translateYVal.get() - 20); } if (e.getCode().equals(KeyCode.DIGIT5)) { translateYVal.set(translateYVal.get() + 20); } if (e.getCode().equals(KeyCode.RIGHT)) { translateXVal.set(translateXVal.get() + 20); } if (e.getCode().equals(KeyCode.LEFT)) { translateXVal.set(translateXVal.get() - 20); } } }); parentBox.setText("BoundsInParent"); parentBox.setFont(new Font(16)); parentBox.setSelected(false); blocksMouseBox.setText("BlocksMouse"); blocksMouseBox.setFont(new Font(16)); blocksMouseBox.setSelected(true); HBox hbox = new HBox(5.0F); hbox.getChildren().clear(); hbox.getChildren().addAll(parentBox, blocksMouseBox); VBox vBox = new VBox(HalfOfButtonH); vBox.setTranslateX(20.0F); vBox.getChildren().clear(); vBox.getChildren().addAll(hbox, listView); ((Group) scene.getRoot()).getChildren().clear(); ((Group) scene.getRoot()).getChildren().addAll(vBox); appFrame.setScene(scene); appFrame.setVisible(true); listView.requestFocus(); } }