/**
  * Create the legalality column, which holds the legality of a filter and also creates a callback
  * to the string property behind it.
  */
 private void setUpLegalityColumn(TableView<FilterInput> tableView) {
   // Set up priority column
   final TableColumn<FilterInput, Boolean> legalColumn = new TableColumn<>("Authorized");
   legalColumn.setMinWidth(70);
   legalColumn.setPrefWidth(70);
   tableView.getColumns().add(legalColumn);
   legalColumn.setCellValueFactory(p -> p.getValue().getLegalProperty());
 }
 /**
  * Create the priority column, which holds the priority of a filter and also creates a callback to
  * the integer property behind it.
  */
 private void setUpPriorityColumn(TableView<FilterInput> tableView) {
   // Set up priority column
   final TableColumn<FilterInput, Integer> priorityColumn = new TableColumn<>("Priority");
   priorityColumn.setMinWidth(50);
   priorityColumn.setPrefWidth(50);
   tableView.getColumns().add(priorityColumn);
   priorityColumn.setCellValueFactory(p -> p.getValue().getPriorityProperty().asObject());
 }
 /**
  * Create the origin column, which holds the type of the origin and also creates a callback to the
  * string property behind it.
  */
 private void setUpOriginColumn(TableView<FilterInput> tableView) {
   // Set up origin column
   final TableColumn<FilterInput, String> originColumn = new TableColumn<>("Filtered By");
   originColumn.setMinWidth(90);
   originColumn.setPrefWidth(90);
   tableView.getColumns().add(originColumn);
   originColumn.setCellValueFactory(p -> p.getValue().getFilterTypeProperty());
 }
 /**
  * Create the type column, which holds the type of the filter and also creates a callback to the
  * string property behind it.
  */
 private void setUpTypeColumn(TableView<FilterInput> tableView) {
   // Set up type column
   final TableColumn<FilterInput, String> typeColumn = new TableColumn<>("Selection Model");
   typeColumn.setMinWidth(90);
   typeColumn.setPrefWidth(90);
   tableView.getColumns().add(typeColumn);
   typeColumn.setCellValueFactory(p -> p.getValue().getSelectionModelProperty());
 }
 /**
  * Create the filter column, which holds the name of the filter and also creates a callback to the
  * string property behind it.
  */
 private void setUpFilterColumn(TableView<FilterInput> tableView) {
   // Set up filter column
   final TableColumn<FilterInput, String> filterColumn = new TableColumn<>("Filter");
   filterColumn.setMinWidth(120);
   filterColumn.setPrefWidth(120);
   tableView.getColumns().add(filterColumn);
   filterColumn.setCellValueFactory(p -> p.getValue().getNameProperty());
 }
  /**
   * 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();
                }));
  }
  /**
   * 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);
                }
              }
            });
  }
  public void initialize(URL location, ResourceBundle resource) {
    bundle = resource;
    double tableViewWidth = 0.98 * JeproLab.APP_WIDTH;
    double remainingWidth = tableViewWidth - 60;
    jeproLabFeedTableView.setPrefWidth(tableViewWidth);
    jeproLabFeedTableView.setLayoutX(0.01 * JeproLab.APP_WIDTH);

    jeproLabFeedIndexColumn.setText("#");
    jeproLabFeedIndexColumn.setPrefWidth(35);
    jeproLabFeedCheckBoxColumn.setText(bundle.getString("JEPROLAB_LABEL"));
    jeproLabFeedCheckBoxColumn.setPrefWidth(25);
    jeproLabFeedTitleColumn.setText(bundle.getString("JEPROLAB_TITLE_LABEL"));
    jeproLabFeedTitleColumn.setPrefWidth(0.15 * remainingWidth);
    jeproLabFeedAuthorColumn.setText(bundle.getString("JEPROLAB_AUTHOR_LABEL"));
    jeproLabFeedAuthorColumn.setPrefWidth(0.15 * remainingWidth);
    jeproLabFeedDescriptionColumn.setText(bundle.getString("JEPROLAB_DESCRIPTION_LABEL"));
    jeproLabFeedDescriptionColumn.getStyleClass().add("text-left");
    jeproLabFeedDescriptionColumn.setPrefWidth(.6 * remainingWidth);
    jeproLabFeedActionColumn.setText(bundle.getString("JEPROLAB_ACTIONS_LABEL"));
    jeproLabFeedActionColumn.setPrefWidth(0.1 * remainingWidth);
  }
  /**
   * createTable is static to allow Army to define a table without having any Actor objects present.
   */
  public static TableView<Actor> createTable() {
    TableView<Actor> table = new TableView<Actor>();
    final double PREF_WIDTH_DOUBLE = 80.0;
    table.setPrefWidth(
        PREF_WIDTH_DOUBLE
            * 7.5); // 7.0 because there are 6 individual columns, but one of those is DOUBLE-WIDTH,
                    // and there is some inter-column spacing
    table.setEditable(true);

    TableColumn<Actor, String> nameCol = new TableColumn<>("Name");
    nameCol.setCellValueFactory(new PropertyValueFactory<Actor, String>("name"));
    nameCol.setPrefWidth(PREF_WIDTH_DOUBLE * 2.0);
    TableColumn<Actor, Number> healthCol = new TableColumn<>("Health");
    healthCol.setCellValueFactory(cell -> cell.getValue().health);
    healthCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    TableColumn<Actor, Number> strengthCol = new TableColumn<>("Strength");
    strengthCol.setCellValueFactory(cell -> cell.getValue().strength);
    strengthCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    TableColumn<Actor, Number> speedCol = new TableColumn<>("Speed");
    speedCol.setCellValueFactory(cell -> cell.getValue().speed);
    speedCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    TableColumn<Actor, Number> locationXCol = new TableColumn<>("X");
    locationXCol.setCellValueFactory(cell -> cell.getValue().getAvatar().translateXProperty());
    locationXCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    TableColumn<Actor, Number> locationYCol = new TableColumn<>("Y");
    locationYCol.setCellValueFactory(cell -> cell.getValue().getAvatar().translateYProperty());
    locationYCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    ObservableList<TableColumn<Actor, ?>> c = table.getColumns();
    c.add(nameCol);
    c.add(healthCol);
    c.add(strengthCol);
    c.add(speedCol);
    c.add(locationXCol);
    c.add(locationYCol);
    // Compare line ABOVE with line BELOW: The BELOW line looks cleaner and does actually work . . .
    // but the compiler spits out a warning. The ABOVE line accomplishes the same thing, less
    // elegantly, but without warnings.
    // table.getColumns().addAll(nameCol, healthCol, strengthCol, speedCol, locationXCol,
    // locationYCol);

    // The following code makes each cell in the selected columns editable (Name, Health, Strength,
    // Speed)
    // We CANNOT implement edit capabilities on the X/Y columns since they are READ-ONLY.
    nameCol.setCellFactory(TextFieldTableCell.<Actor>forTableColumn());
    nameCol.setOnEditCommit(
        event -> {
          Actor a = (event.getTableView().getItems().get(event.getTablePosition().getRow()));
          a.setName(event.getNewValue());
          a.resetAvatarAttributes();
        });

    healthCol.setCellFactory(
        TextFieldTableCell.<Actor, Number>forTableColumn(new NumberStringConverter()));
    healthCol.setOnEditCommit(
        event -> {
          Actor a = (event.getTableView().getItems().get(event.getTablePosition().getRow()));
          a.setHealth((Double) event.getNewValue());
          a.resetAvatarAttributes();
        });

    strengthCol.setCellFactory(
        TextFieldTableCell.<Actor, Number>forTableColumn(new NumberStringConverter()));
    strengthCol.setOnEditCommit(
        event -> {
          Actor a = (event.getTableView().getItems().get(event.getTablePosition().getRow()));
          a.setStrength((Double) event.getNewValue());
          a.resetAvatarAttributes();
        });

    speedCol.setCellFactory(
        TextFieldTableCell.<Actor, Number>forTableColumn(new NumberStringConverter()));
    speedCol.setOnEditCommit(
        event -> {
          Actor a = (event.getTableView().getItems().get(event.getTablePosition().getRow()));
          a.setSpeed((Double) event.getNewValue());
          a.resetAvatarAttributes();
        });

    return table;
  } // end createTable()
Example #10
0
  public void addList(GridPane grid) {
    tableView.setEditable(false);

    Callback<TableColumn, TableCell> integerCellFactory =
        new Callback<TableColumn, TableCell>() {
          @Override
          public TableCell call(TableColumn p) {
            MyIntegerTableCell cell = new MyIntegerTableCell();
            cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new MyEventHandler());
            return cell;
          }
        };

    Callback<TableColumn, TableCell> stringCellFactory =
        new Callback<TableColumn, TableCell>() {
          @Override
          public TableCell call(TableColumn p) {
            MyStringTableCell cell = new MyStringTableCell();
            cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new MyEventHandler());
            return cell;
          }
        };

    Callback<TableColumn, TableCell> activeCellFactory =
        new Callback<TableColumn, TableCell>() {
          @Override
          public TableCell call(TableColumn p) {
            MyStringTableCell cell = new MyStringTableCell();
            cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new MyEventHandler());
            return cell;
          }
        };

    TableColumn colId = new TableColumn("ID");
    colId.setCellValueFactory(new PropertyValueFactory<Record, String>("id"));
    colId.setCellFactory(integerCellFactory);
    colId.setPrefWidth(30);

    TableColumn colName = new TableColumn("Name");
    colName.setCellValueFactory(new PropertyValueFactory<Record, String>("name"));
    colName.setCellFactory(stringCellFactory);
    colName.setPrefWidth(140);

    TableColumn colBoardWidth = new TableColumn("Width");
    colBoardWidth.setCellValueFactory(new PropertyValueFactory<Record, String>("BoardWidth"));
    colBoardWidth.setCellFactory(integerCellFactory);
    colBoardWidth.setPrefWidth(75);

    TableColumn colBoardHeight = new TableColumn("Height");
    colBoardHeight.setCellValueFactory(new PropertyValueFactory<Record, String>("BoardHeight"));
    colBoardHeight.setCellFactory(integerCellFactory);
    colBoardHeight.setPrefWidth(75);

    TableColumn colActive = new TableColumn("Acitve");
    colActive.setCellValueFactory(new PropertyValueFactory<Record, String>("Active"));
    colActive.setCellFactory(activeCellFactory);
    colActive.setPrefWidth(70);

    tableView.setItems(recordList);
    tableView.getColumns().addAll(colId, colName, colBoardWidth, colBoardHeight, colActive);
    tableView.setPrefSize(400, 400);
    grid.add(tableView, 0, 0);
  }