コード例 #1
0
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    try {

      fillTableFromData();
      action.setSortable(false);

      action.setCellValueFactory(
          new Callback<
              TableColumn.CellDataFeatures<EmployeeVO, Boolean>, ObservableValue<Boolean>>() {

            @Override
            public ObservableValue<Boolean> call(
                TableColumn.CellDataFeatures<EmployeeVO, Boolean> p) {
              return new SimpleBooleanProperty(p.getValue() != null);
            }
          });

      action.setCellFactory(
          new Callback<TableColumn<EmployeeVO, Boolean>, TableCell<EmployeeVO, Boolean>>() {

            @Override
            public TableCell<EmployeeVO, Boolean> call(TableColumn<EmployeeVO, Boolean> p) {
              return new ButtonCell();
            }
          });

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  private void setupTracksView() {
    TableColumn titleColumn = new TableColumn("Title");
    titleColumn.setSortable(false);
    titleColumn.setMinWidth(USE_COMPUTED_SIZE);
    titleColumn.setCellValueFactory(new PropertyValueFactory<>("title"));

    TableColumn durationColumn = new TableColumn("Duration");
    durationColumn.setMinWidth(60);
    durationColumn.setMaxWidth(60);
    durationColumn.setSortable(false);
    durationColumn.setCellValueFactory(new PropertyValueFactory<>("durationFormatted"));
    durationColumn.getStyleClass().add("text-layout-center");

    tracksView.getColumns().clear();
    tracksView.getColumns().addAll(titleColumn, durationColumn);
    tracksView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
  }
コード例 #3
0
  @SuppressWarnings("unchecked")
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    tableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    TableViewSearchable<ImageResource> searchable = new TableViewSearchable<>(tableView);
    searchable.setCaseSensitive(false);

    TableColumn<ImageResource, String> tc =
        (TableColumn<ImageResource, String>) tableView.getColumns().get(0);
    tc.setCellValueFactory(new PropertyValueFactory<>("href"));
    tc.setSortable(true);

    TableColumn<ImageResource, Image> tc2 =
        (TableColumn<ImageResource, Image>) tableView.getColumns().get(1);
    tc2.setCellValueFactory(new PropertyValueFactory<>("cover"));
    tc2.setCellFactory(new ImageCellFactory<>(null, 100d));
    tc2.setSortable(false);

    tableView
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            new ChangeListener<ImageResource>() {
              @Override
              public void changed(
                  ObservableValue<? extends ImageResource> observable,
                  ImageResource oldValue,
                  ImageResource newValue) {
                refreshImageView(newValue);
              }
            });
    tableView.setOnMouseClicked(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            if (event.getButton().equals(MouseButton.PRIMARY)) {
              if (event.getClickCount() == 2) {
                insertCover();
              }
            }
          }
        });
    instance = this;
  }
コード例 #4
0
  private void setupPlaylistsView() {
    TableColumn titleColumn = new TableColumn("Title");
    titleColumn.setMinWidth(USE_COMPUTED_SIZE);
    titleColumn.setSortable(false);
    titleColumn.setCellValueFactory(new PropertyValueFactory<>("title"));

    TableColumn countColumn = new TableColumn("Tracks");
    countColumn.setMinWidth(60);
    countColumn.setMaxWidth(60);
    countColumn.setSortable(false);
    countColumn.setCellValueFactory(new PropertyValueFactory<>("count"));
    countColumn.getStyleClass().add("text-layout-right");

    playlistsView.getColumns().clear();
    playlistsView.getColumns().addAll(titleColumn, countColumn);
    playlistsView.setContextMenu(playlistsContextMenu);
    playlistsView.setPlaceholder(playlistPlaceholder);
    playlistsView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
  }
コード例 #5
0
  /**
   * Create the active column, which holds the activity state and also creates a callback to the
   * string property behind it.
   */
  private void setUpActiveColumn(TableView<FilterInput> tableView) {
    // Set up active column
    final TableColumn<FilterInput, Boolean> activeColumn = new TableColumn<>("Active");
    activeColumn.setMinWidth(50);
    activeColumn.setPrefWidth(50);
    tableView.getColumns().add(activeColumn);
    activeColumn.setSortable(false);

    activeColumn.setCellFactory(
        CheckBoxTableCell.forTableColumn(
            (Callback<Integer, ObservableValue<Boolean>>)
                param -> {
                  final FilterInput input = tableView.getItems().get(param);
                  input
                      .getActiveProperty()
                      .addListener(
                          l -> {
                            notifyUpdateCommand(input);
                          });
                  return input.getActiveProperty();
                }));
  }
コード例 #6
0
  /**
   * Create the color column, which holds the color and also creates a callback to the string
   * property behind it.
   */
  private void setUpColorColumn(TableView<FilterInput> tableView) {
    final TableColumn<FilterInput, Color> colorColumn = new TableColumn<>("Color");
    colorColumn.setMinWidth(50);
    colorColumn.setPrefWidth(50);
    colorColumn.setSortable(false);
    tableView.getColumns().add(colorColumn);

    // Set the cell value factory for the color
    colorColumn.setCellValueFactory(p -> p.getValue().getColorProperty());

    // Set the cell factory for the color
    colorColumn.setCellFactory(
        param ->
            new TableCell<FilterInput, Color>() {

              final Rectangle rectangle = new Rectangle();

              @Override
              public void updateItem(Color item, boolean empty) {
                // Add the color to the row
                if (item != null) {
                  HBox hBox = new HBox();
                  hBox.getChildren().add(rectangle);
                  rectangle.setHeight(20);
                  rectangle.setWidth(30);
                  hBox.setAlignment(Pos.CENTER);

                  rectangle.setFill(item);

                  setGraphic(hBox);
                }

                // Remove the color if the row has been removed
                if (empty) {
                  setGraphic(null);
                }
              }
            });
  }