Javafx select multiple rows

Tolga Tamer picture Tolga Tamer · Mar 22, 2014 · Viewed 22.2k times · Source

I m trying to select multiple rows in javafx but i dont want to use keyboard (SHIFT)for that.it should be after i click on it selected and when i click on an other column it should be selected as well.

I check some other answers here but i couldnt 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);

Answer

jewelsea picture jewelsea · Mar 22, 2014
tableView.getSelectionModel().setSelectionMode(
    SelectionMode.MULTIPLE
);