Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2017 17:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
JavaFX: Eliminación item de un ListView
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
public void start(Stage primaryStage) throws Exception {
ListView<String> listView = new ListView<>();
ObservableList<String> items = FXCollections.observableArrayList("Uno", "Dos", "Tres", "Cuatro");
Button eliminarButton = new Button("Eliminar");
eliminarButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
int posicionAEliminar = listView.getSelectionModel().getSelectedIndex();
System.out.println(">" + posicionAEliminar);
if (posicionAEliminar >= 0) {
} else {
System.out.println("No se puede eliminar, nada seleccionado.");
VBox vBox = new VBox();
vBox.setPadding(new Insets(20, 20, 20, 20));
Scene scene = new Scene(vBox, 400, 400);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment