Java Code Examples for javafx.scene.control.TableColumn#setSortable()

The following examples show how to use javafx.scene.control.TableColumn#setSortable() . 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: TableVisualisation.java    From constellation with Apache License 2.0 6 votes vote down vote up
public void addColumn(final String columnName, final int percentWidth) {
    final TableColumn<C, Object> column = new TableColumn<>(columnName);
    tableColumns.put(columnName, column);

    column.prefWidthProperty().bind(table.widthProperty().multiply(percentWidth / 100.0));

    column.setCellValueFactory(cellData -> new SimpleObjectProperty<>(translator.getCellData(cellData.getValue(), columnName)));

    column.setCellFactory(columnData -> {
        return new TableCell<C, Object>() {
            @Override
            public void updateItem(final Object item, final boolean empty) {
                super.updateItem(item, empty);
                if (item != null) {
                    this.setText(translator.getCellText(this.getTableRow().getItem(), item, columnName));
                    final ConstellationColor color = translator.getCellColor(this.getTableRow().getItem(), item, columnName);
                    this.setBackground(new Background(new BackgroundFill(color.getJavaFXColor(), CornerRadii.EMPTY, Insets.EMPTY)));
                }
            }
        };
    });

    column.setSortable(true);

    table.getColumns().add(column);
}
 
Example 2
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param index Column index, -1 to add to end
 *  @param header Header text
 */
private void createTableColumn(final int index, final String header)
{
    final TableColumn<List<ObservableCellValue>, CellValue> table_column = new TableColumn<>(header);
    table_column.setCellValueFactory(VALUE_FACTORY);
    // Prevent column re-ordering
    // (handled via moveColumn which also re-orders the data)
    table_column.setReorderable(false);

    // By default, use text field editor. setColumnOptions() can replace
    table_column.setCellFactory(list -> new StringTextCell());
    table_column.setOnEditStart(event -> editing = true);
    table_column.setOnEditCommit(event ->
    {
        editing = false;
        final int col = event.getTablePosition().getColumn();
        List<ObservableCellValue> row = event.getRowValue();
        if (row == MAGIC_LAST_ROW)
        {
            // Entered in last row? Create new row
            row = createEmptyRow();
            final List<List<ObservableCellValue>> data = table.getItems();
            data.add(data.size()-1, row);
        }
        row.get(col).setValue(event.getNewValue());
        fireDataChanged();

        // Automatically edit the next row, same column
        editCell(event.getTablePosition().getRow() + 1, table_column);
    });
    table_column.setOnEditCancel(event -> editing = false);
    table_column.setSortable(false);

    if (index >= 0)
        table.getColumns().add(index, table_column);
    else
        table.getColumns().add(table_column);
}
 
Example 3
Source File: FilterGridController.java    From VocabHunter with Apache License 2.0 5 votes vote down vote up
private TableColumn<GridLine, GridCell> buildColumn(final FilterGridModel filterModel, final int index) {
    TableColumn<GridLine, GridCell> column = new TableColumn<>(columnNameTool.columnName(index));

    column.setSortable(false);
    column.setCellValueFactory(features -> extractValue(features, index));
    column.setCellFactory(c -> new FilterGridWordTableCell(filterModel.getColumnSelections().get(index)));
    if (isScrollableColumnList(filterModel)) {
        column.setPrefWidth(PREFERRED_COLUMN_WIDTH);
    }

    return column;
}
 
Example 4
Source File: LoadingColumn.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus> getTableColumn() {
    TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus> tableColumn = new TableColumn<>(getColumnTitle());
    tableColumn.setCellFactory(cellFactory());
    tableColumn.setCellValueFactory(cellValueFactory());
    tableColumn.setComparator(null);
    tableColumn.setSortable(false);
    tableColumn.setMaxWidth(26);
    tableColumn.setMinWidth(26);
    return tableColumn;
}
 
Example 5
Source File: SQLColumnSettingsComponent.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public SQLColumnSettingsComponent() {
    columnsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    value = new SQLColumnSettings();
    TableColumn<SQLRowObject,String> columnName=new TableColumn<SQLRowObject,String> (value.getColumnName(0));
    TableColumn<SQLRowObject,SQLExportDataType>  columnType=new TableColumn<SQLRowObject,SQLExportDataType> (value.getColumnName(1));
    TableColumn<SQLRowObject,String>  columnValue= new TableColumn<SQLRowObject,String> (value.getColumnName(2));

    columnName.setCellValueFactory(new PropertyValueFactory<>("Name")); //this is needed during connection to a database
    columnType.setCellValueFactory(new PropertyValueFactory<>("Type"));
    columnValue.setCellValueFactory(new PropertyValueFactory<>("Value"));

    columnsTable.getColumns().addAll(columnName,columnType,columnValue);  //added all the columns in the table
    setValue(value);
    columnsTable.setStyle("-fx-selection-bar: #3399FF; -fx-selection-bar-non-focused: #E3E3E3;"); //CSS color change on selection of row


    columnsTable.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    columnName.setSortable(false);
    columnValue.setSortable(false);
    columnType.setSortable(false);

    columnName.setReorderable(false);
    columnValue.setReorderable(false);
    columnType.setReorderable(false);

    columnsTable.setPrefSize(550, 220);
    columnsTable.setFixedCellSize(columnsTable.getFixedCellSize()+20);
    columnsTable.setStyle("-fx-font: 10 \"Plain\"");

    //Setting action event on cells
    columnsTable.getSelectionModel().setCellSelectionEnabled(true);  //individual cell selection enabled
    columnsTable.setEditable(true);

    //Editors on each cell
  columnName.setCellFactory(TextFieldTableCell.<SQLRowObject>forTableColumn());
  columnName.setOnEditCommit(event -> {
    getValue().setValueAt(event.getNewValue(), event.getTablePosition().getRow(), 0);
    setValue(getValue()); //refresh the table
  });

  columnValue.setCellFactory(TextFieldTableCell.<SQLRowObject>forTableColumn());
  columnValue.setOnEditCommit(event -> {
    getValue().setValueAt(event.getNewValue().toUpperCase(), event.getTablePosition().getRow(), 2);
    setValue(getValue()); //refresh the table
  });

  ArrayList<SQLExportDataType> exportDataTypeValues=new ArrayList<SQLExportDataType>(Arrays.asList(SQLExportDataType.values()));

  columnType.setCellFactory(ComboBoxTableCell.forTableColumn(FXCollections.observableArrayList(SQLExportDataType.values())));
  columnType.setOnEditCommit(event -> {
    boolean selected = event.getNewValue().isSelectableValue();
    if(!selected){ //case of  invalid(Title) datatype selection
      getValue().setValueAt(exportDataTypeValues.get(exportDataTypeValues.indexOf(event.getNewValue())+1),event.getTablePosition().getRow(),1);
    }
    else {
      getValue().setValueAt(event.getNewValue(), event.getTablePosition().getRow(), 1);
    }
    setValue(getValue());
  });

    // Add buttons
    VBox buttonsPanel=new VBox(20);
    addColumnButton=new Button("Add");
    removeColumnButton=new Button("Remove");
    addColumnButton.setOnAction(this::actionPerformed);
    removeColumnButton.setOnAction(this::actionPerformed);
    buttonsPanel.getChildren().addAll(addColumnButton,removeColumnButton);


    this.setRight(buttonsPanel);
    this.setCenter(columnsTable);
    BorderPane.setMargin(buttonsPanel, new Insets(10));

}