Javafx 选择多行
我试图在JavaFX中选择多行,但我不想使用键盘(即SHIFT键)。它应该在我点击它之后选择,当我点击另一列时,它也应该被选中。
我在这里检查了一些其他答案,但我找不到一些简短而方便的东西。有没有更短的方法可以做到这一点?
@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);