private void createColumns(List<TableModelDVO> columns) { ObservableList<TableColumn<Map<String, Object>, ?>> tableColumns = tbResult.getColumns(); for (TableModelDVO column : columns) { String databaseColumnName = column.getDatabaseColumnName(); TableColumn e = new TableColumn(databaseColumnName); e.setCellValueFactory(new MapValueFactory<Object>(databaseColumnName)); tableColumns.add(e); } }
/** * Event who add dynamically column in poll */ @FXML public void addTimeSlotAction() { LOGGER.info("Add time slot..."); String dateFrom = departureDateField.getText(); String timeFrom = departureTimeField.getText(); String dateTo = endDateField.getText(); String timeTo = endTimeField.getText(); // Add time slot to the current model TimeSlot timeSlot = new TimeSlot.Builder() .setFrom(dateFrom + " " + timeFrom) .setTo(dateTo + " " + timeTo) .build(); this.opinionPoll.getTimeSlots().add(timeSlot); this.departureTimeField.setText(""); this.endTimeField.setText(""); LOGGER.debug("current opinion poll: " + opinionPoll.toString()); // Add colomn to the tableView String newNameColumn = dateFrom + " - " + timeFrom + "\n" + dateTo + " - " + timeTo; TableColumn<Map, String> column = new TableColumn<>(newNameColumn); column.setCellValueFactory(new MapValueFactory(newNameColumn)); column.setMinWidth(newNameColumn.length()); tableViewPoll.getColumns().add(column); }
@SuppressWarnings("restriction") public TableView createGUI() { for (int x = 0; x < NUM_COLUMNS; x++) { TableColumn<Map, String> col = new TableColumn<>(headers[x]); col.setCellValueFactory(new MapValueFactory(x)); col.setMinWidth(col_widths[x]); cols.add(col); } table_view = new TableView<>(generateDataInMap()); table_view.setEditable(true); table_view.getSelectionModel().setCellSelectionEnabled(true); table_view.getColumns().setAll(cols.get(0), cols.get(1), cols.get(2), cols.get(3), cols.get(4), cols.get(5), cols.get(6)); Callback<TableColumn<Map, String>, TableCell<Map, String>> cellFactoryForMap = new Callback<TableColumn<Map, String>, TableCell<Map, String>>() { @Override public TableCell call(TableColumn p) { return new TextFieldTableCell(new StringConverter() { @Override public String toString(Object o) { //updateSettlementInfo(); //System.out.println("t.toString() is "+ t.toString()); //validationSupport.registerValidator((TextField) o, Validator.createEmptyValidator("Text is required")); return o.toString(); } @Override public Object fromString(String s) { //updateSettlementInfo(); //System.out.println("string() is "+ string); return s; } }); } }; for (int x = 0; x < NUM_COLUMNS; x++) { cols.get(x).setCellFactory(cellFactoryForMap); } return table_view; }
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Mars Simulation Project"); stage.setWidth(300); stage.setHeight(500); final Label label = new Label("Configuring your settlement(s)"); label.setFont(new Font("Arial", 20)); TableColumn<Map, String> firstDataColumn = new TableColumn<>("Settlement"); TableColumn<Map, String> secondDataColumn = new TableColumn<>("Template"); firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey)); firstDataColumn.setMinWidth(130); secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey)); secondDataColumn.setMinWidth(130); TableView table_view = new TableView<>(generateDataInMap()); table_view.setEditable(true); table_view.getSelectionModel().setCellSelectionEnabled(true); table_view.getColumns().setAll(firstDataColumn, secondDataColumn); Callback<TableColumn<Map, String>, TableCell<Map, String>> cellFactoryForMap = new Callback<TableColumn<Map, String>, TableCell<Map, String>>() { @Override public TableCell call(TableColumn p) { return new TextFieldTableCell(new StringConverter() { @Override public String toString(Object t) { return t.toString(); } @Override public Object fromString(String string) { return string; } }); } }; firstDataColumn.setCellFactory(cellFactoryForMap); secondDataColumn.setCellFactory(cellFactoryForMap); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); vbox.getChildren().addAll(label, table_view); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.show(); }
public void setTableColumnProperties(final double percentage, final String valueName, final boolean linkCursor) { setWidthPercentage(percentage); myTableColumn.setCellValueFactory(new MapValueFactory<String>(valueName)); myTableColumn.setCellFactory(createObjectCellFactory(linkCursor)); }