Multi-screen selection TableView returns one of the selected objects as null. This does not happen every time, but most often it happens when I try to select two rows in a table. similar to the problem posed in this question
The best way to reproduce the problem is to try selecting two consecutive lines. FXML:
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.ProgressBar?> <?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableView?> <?import javafx.scene.control.TextField?> <?import javafx.scene.control.cell.PropertyValueFactory?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.Region?> <?import javafx.scene.layout.StackPane?> <AnchorPane xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.test.controller.TestController"> <children> <TableView fx:id="personsTable" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="35.0"> <placeholder> <Label text="" /> </placeholder> <columns> <TableColumn text="Name"> <cellValueFactory> <PropertyValueFactory property="name" /> </cellValueFactory> </TableColumn> <TableColumn text="Address"> <cellValueFactory> <PropertyValueFactory property="address" /> </cellValueFactory> </TableColumn> <TableColumn text="Course"> <cellValueFactory> <PropertyValueFactory property="course" /> </cellValueFactory> </TableColumn> <TableColumn text="Country"> <cellValueFactory> <PropertyValueFactory property="country" /> </cellValueFactory> </TableColumn> </columns> </TableView> </children> </AnchorPane>
Controller:
import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import com.test.model.Person; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.ContextMenu; import javafx.scene.control.MenuItem; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableView; public class TestController implements Initializable { @FXML TableView<Person> personsTable = new TableView<Person>(); @Override public void initialize(URL location, ResourceBundle resources) {
Model:
public class Person { public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public String getCourse() { return course; } public void setCourse(String course) { this.course = course; } private String name; private String address; private String country; private String course; }
javafx-8 tableview multi-select
user68883
source share