本文整理汇总了Java中javafx.scene.control.TableView.getSelectionModel方法的典型用法代码示例。如果您正苦于以下问题:Java TableView.getSelectionModel方法的具体用法?Java TableView.getSelectionModel怎么用?Java TableView.getSelectionModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.TableView
的用法示例。
在下文中一共展示了TableView.getSelectionModel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: selectCells
import javafx.scene.control.TableView; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") public void selectCells(TableView<?> tableView, String value) {
@SuppressWarnings("rawtypes")
TableViewSelectionModel selectionModel = tableView.getSelectionModel();
selectionModel.clearSelection();
JSONObject cells = new JSONObject(value);
JSONArray object = (JSONArray) cells.get("cells");
for (int i = 0; i < object.length(); i++) {
JSONArray jsonArray = object.getJSONArray(i);
int rowIndex = Integer.parseInt(jsonArray.getString(0));
int columnIndex = getColumnIndex(jsonArray.getString(1));
@SuppressWarnings("rawtypes")
TableColumn column = tableView.getColumns().get(columnIndex);
if (getVisibleCellAt(tableView, rowIndex, columnIndex) == null) {
tableView.scrollTo(rowIndex);
tableView.scrollToColumn(column);
}
selectionModel.select(rowIndex, column);
}
}
示例2: marathon_select
import javafx.scene.control.TableView; //导入方法依赖的package包/类
@Override public boolean marathon_select(String value) {
TableView<?> tableView = (TableView<?>) node;
TableViewSelectionModel<?> selectionModel = tableView.getSelectionModel();
if ("".equals(value)) {
selectionModel.clearSelection();
return true;
} else if (value.equals("all")) {
int rowSize = tableView.getItems().size();
for (int i = 0; i < rowSize; i++) {
selectionModel.select(i);
}
return true;
} else if (selectionModel.isCellSelectionEnabled()) {
selectCells(tableView, value);
return true;
} else {
int[] selectedRows = getSelectedRows(value);
selectionModel.clearSelection();
for (int rowIndex : selectedRows) {
if (getVisibleCellAt(tableView, rowIndex, tableView.getColumns().size() - 1) == null) {
tableView.scrollTo(rowIndex);
}
selectionModel.select(rowIndex);
}
return true;
}
}
示例3: getSelection
import javafx.scene.control.TableView; //导入方法依赖的package包/类
public String getSelection(TableView<?> tableView) {
TableViewSelectionModel<?> selectionModel = tableView.getSelectionModel();
if (!selectionModel.isCellSelectionEnabled()) {
ObservableList<Integer> selectedIndices = selectionModel.getSelectedIndices();
if (tableView.getItems().size() == selectedIndices.size()) {
return "all";
}
if (selectedIndices.size() == 0) {
return "";
}
return getRowSelectionText(selectedIndices);
}
@SuppressWarnings("rawtypes")
ObservableList<TablePosition> selectedCells = selectionModel.getSelectedCells();
int[] rows = new int[selectedCells.size()];
int[] columns = new int[selectedCells.size()];
int rowCount = tableView.getItems().size();
int columnCount = tableView.getColumns().size();
if (selectedCells.size() == rowCount * columnCount) {
return "all";
}
if (selectedCells.size() == 0) {
return "";
}
JSONObject cells = new JSONObject();
JSONArray value = new JSONArray();
for (int i = 0; i < selectedCells.size(); i++) {
TablePosition<?, ?> cell = selectedCells.get(i);
rows[i] = cell.getRow();
columns[i] = cell.getColumn();
List<String> cellValue = new ArrayList<>();
cellValue.add(cell.getRow() + "");
cellValue.add(getColumnName(tableView, cell.getColumn()));
value.put(cellValue);
}
cells.put("cells", value);
return cells.toString();
}
示例4: addTableAndListView
import javafx.scene.control.TableView; //导入方法依赖的package包/类
private void addTableAndListView() {
FilteredList<Movie> filteredList = new FilteredList<>(database.getMovies());
filteredList.predicateProperty().bind(getSkinnable().filterPredicateProperty());
SortedList<Movie> tableViewSortedList = new SortedList<>(filteredList);
TableView<Movie> tableView = new MovieTableView();
tableViewSortedList.comparatorProperty().bind(tableView.comparatorProperty());
tableView.setItems(tableViewSortedList);
TableViewSelectionModel<Movie> tableViewSelectionModel = tableView.getSelectionModel();
tableViewSelectionModel.selectedItemProperty().addListener(it -> getSkinnable().setSelectedMovie(tableViewSelectionModel.getSelectedItem()));
PrettyListView<Movie> listView = new PrettyListView<>();
listView.setItems(filteredList);
MultipleSelectionModel<Movie> listViewSelectionModel = listView.getSelectionModel();
listViewSelectionModel.selectedItemProperty().addListener(it -> getSkinnable().setSelectedMovie(listViewSelectionModel.getSelectedItem()));
listView.setOnMouseClicked(evt -> {
if (evt.getButton() == MouseButton.PRIMARY && evt.getClickCount() == 2) {
showTrailer();
}
});
getSkinnable().useListViewCellFactoryProperty().addListener(it -> {
if (getSkinnable().isUseListViewCellFactory()) {
listView.setCellFactory(view -> new MovieCell(getSkinnable()));
} else {
listView.setCellFactory(view -> new ListCell<Movie>() {
@Override
protected void updateItem(Movie item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setText(item.toString());
}
}
});
}
});
getSkinnable().selectedMovieProperty().addListener(it -> {
tableViewSelectionModel.select(getSkinnable().getSelectedMovie());
listViewSelectionModel.select(getSkinnable().getSelectedMovie());
});
FlipPanel flipPanel = new FlipPanel();
flipPanel.setFlipDirection(Orientation.HORIZONTAL);
flipPanel.getFront().getChildren().add(tableView);
flipPanel.getBack().getChildren().add(listView);
getSkinnable().useListViewProperty().addListener(it -> {
if (getSkinnable().isUseListView()) {
flipPanel.flipToBack();
if (getSkinnable().isUseListViewCellFactory()) {
listView.setCellFactory(view -> new MovieCell(getSkinnable()));
}
} else {
flipPanel.flipToFront();
}
});
GridPane.setVgrow(flipPanel, Priority.ALWAYS);
container.add(flipPanel, 1, 2);
}