import javafx.application.Application; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ListView; import javafx.scene.layout.VBox; public class App extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { ListView list = new ListView<>(); list.getItems().setAll("alma", "körte", "barack", "szilva"); Button button = new Button("Mehet"); button.setOnAction(e -> { System.out.println(list.getSelectionModel().getSelectedIndex()); System.out.println(list.getSelectionModel().getSelectedItem()); }); VBox vbox = new VBox(10); vbox.setPadding(new Insets(10, 10, 10, 10)); vbox.getChildren().addAll(list, button); Scene scene = new Scene(vbox, 300, 250); primaryStage.setScene(scene); primaryStage.show(); } }