Javafx select multiple rows
java, javafx, tableview
Solution
tableView.getSelectionModel().setSelectionMode(
SelectionMode.MULTIPLE
);
Problem
I'm trying to select multiple rows in JavaFX but I don't want to use keyboard (i.e. SHIFT key) for that. It should be selected after I click on it and when I click on another column it should be selected as well. I checked some other answers here but I couldn't find something short and handy. Is there a shorter way to do it? ``` @FXML private static Logger logger = Logger.getLogger(MainFrameControl.class); public TableView<Box> boxTable; protected final ObservableList<Box> boxData = FXCollections.observableArrayList(); Service service = new ServiceImpl(); private Stage mainStage; public MainFrameControl(Stage mainStage) { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainFrame.fxml")); fxmlLoader.setRoot(this); fxmlLoader.setController(this); this.mainStage = mainStage; Stage stage = new Stage(); try { fxmlLoader.load(); } catch (IOException exception) { throw new RuntimeException(exception); } ArrayList<Box> list = service.findAllBoxen(); TableColumn<Box, String> boxnameColumn = (TableColumn<Box, String>) boxTable.getColumns().get(0); boxnameColumn.setCellValueFactory(new PropertyValueFactory<Box, String>("boxName")); TableColumn<Box, String> sizeColumn = (TableColumn<Box, String>) boxTable.getColumns().get(1); sizeColumn.setCellValueFactory(new PropertyValueFactory<Box, String>("size")); TableColumn<Box, String> windowColumn = (TableColumn<Box, String>) boxTable.getColumns().get(2); windowColumn.setCellValueFactory(new PropertyValueFactory<Box, String>("window")); TableColumn<Box, String> costColumn = (TableColumn<Box, String>) boxTable.getColumns().get(3); costColumn.setCellValueFactory(new PropertyValueFactory<Box, String>("cost")); TableColumn<Box, String> locationColumn = (TableColumn<Box, String>) boxTable.getColumns().get(4); locationColumn.setCellValueFactory(new PropertyValueFactory<Box, String>("location")); TableColumn<Box, Boolean> beddingColumn = (TableColumn<Box, Boolean>) boxTable.getColumns().get(5); beddingColumn.setCellValueFactory(new PropertyValueFactory<Box, Boolean>("bedding")); boxTable.setItems(boxData); ```