【发布时间】:2014-04-30 05:36:48
【问题描述】:
我正在尝试在 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);
【问题讨论】:
-
我会添加一个多选按钮,比如 android。单击按钮,随后的选择将被添加(或可能在再次单击后被删除)到选择列表中。
-
你能给出一个javafx中的代码示例吗?