package graphics.api.control; import javafx.event.EventHandler; import javafx.application.Application; import javafx.scene.control.*; import javafx.stage.*; import javafx.scene.*; import javafx.scene.input.*; import javafx.collections.ObservableList; public class ListViewIssue extends Application { public static void main(String[] args) { ListViewIssue.launch(args); } ObservableList listItems = javafx.collections.FXCollections.observableArrayList(); boolean defContents = true; ListView listView = new ListView(); @Override public void start(Stage appFrame) throws Exception { float buttonH = 20;//TODO: Fix me getButtonHeight(5, getH()); for (int i = 1; i <= 10; i++) { listItems.add("List View Pannable Item " + i); } listView.getItems().clear(); listView.getItems().addAll(listItems); listView.setTranslateX(10.0F); //listView.getTransforms().clear(); listView.setPrefWidth(5 * 400 / 12); listView.setPrefHeight(6 * buttonH); listView.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent ke) { if (ke.getCode().equals(KeyCode.LEFT)) { if (defContents) { listItems = javafx.collections.FXCollections.observableArrayList(); for (int i = 1; i <= 20; i++) { TextField textbox = new TextField(); textbox.setText("List View Pannable Item " + i); //textbox.setFont(new Font(getFontSize()));//Not needed //textbox.setStyle("-fx-font: " + getFontSize() + "px \"Serif\";"); listItems.add(textbox); } defContents = false; } else { listItems = javafx.collections.FXCollections.observableArrayList(); for (int i = 1; i <= 20; i++) { listItems.add("List View Pannable Item " + i); } defContents = true; } listView.getItems().clear(); listView.getItems().addAll(listItems); } } }); Scene scene = new Scene(new Group(), 400, 400); ((Group) scene.getRoot()).getChildren().clear(); ((Group) scene.getRoot()).getChildren().addAll(listView); appFrame.setScene(scene); appFrame.setVisible(true); listView.requestFocus(); } }