Java Code Examples for javafx.scene.control.TableView.TableViewSelectionModel#select()

The following examples show how to use javafx.scene.control.TableView.TableViewSelectionModel#select() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 7 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Set selection
 *  @param sel_row_col Flattened list of row, col, row, col, .. cell indices. May be <code>null</code>
 */
public void setSelection(final List<Integer> sel_row_col)
{
    final TableViewSelectionModel<List<ObservableCellValue>> selection = table.getSelectionModel();
    selection.clearSelection();

    if (sel_row_col == null)
        return;

    final ObservableList<TableColumn<List<ObservableCellValue>, ?>> columns = table.getColumns();
    int i = 0;
    while (i < sel_row_col.size())
    {
        final int row = sel_row_col.get(i++);
        final int col = sel_row_col.get(i++);
        if (row < data.size()  &&  col < columns.size())
            selection.select(row, columns.get(col));
    }
}
 
Example 3
Source File: JavaFXTableViewElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@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;
    }
}