package tests; import javafx.application.Application; import javafx.collections.ListChangeListener; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ListView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.StackPane; import javafx.stage.Popup; import javafx.stage.Stage; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author sjiang */ public class MyListView extends Application { public static void main(String[] args) throws Exception { Application.launch(args); } @Override public void start(Stage stage) throws Exception { final StackPane sp = new StackPane(); final Button button = new Button("click") { @Override public void fire() { final Popup popup = new Popup(); final ListView listView = new ListView(); listView.setPrefSize(300, 300); int count = 0; while (count++ <= 10) { listView.getItems().add("Item-" + count); } listView.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { @Override public void handle(MouseEvent me) { System.out.println("---ListView is clicked"); if (me.isShiftDown()) { System.out.println("---call listView.setPrefSize(8000, 8000)"); listView.setPrefSize(8000, 8000); } // popup.hide(); } }); popup.getContent().add(listView); popup.show(sp, 0, 0); } }; sp.getChildren().add(button); Scene scene = new Scene(sp); stage.setScene(scene); stage.setVisible(true); } }