Javafx选择多行 [英] Javafx select multiple rows
本文介绍了Javafx选择多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在javafx中选择多行,但我不想使用键盘(SHIFT)。应该在我点击它之后选择它,当我点击另一列时它也应该被选中。
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);
推荐答案
tableView.getSelectionModel().setSelectionMode(
SelectionMode.MULTIPLE
);
这篇关于Javafx选择多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文