List of usage examples for javafx.scene.control TableColumn setOnEditCommit
public final void setOnEditCommit(EventHandler<CellEditEvent<S, T>> value)
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setWidth(450);//from w w w .j a v a 2 s . co m stage.setHeight(550); table.setEditable(true); TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name"); firstNameCol.setMinWidth(100); firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName")); firstNameCol.setCellFactory(TextFieldTableCell.<Person>forTableColumn()); firstNameCol.setOnEditCommit((CellEditEvent<Person, String> t) -> { ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setFirstName(t.getNewValue()); }); TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name"); lastNameCol.setMinWidth(100); lastNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName")); lastNameCol.setCellFactory(TextFieldTableCell.<Person>forTableColumn()); lastNameCol.setOnEditCommit((CellEditEvent<Person, String> t) -> { ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setLastName(t.getNewValue()); }); table.setItems(data); table.getColumns().addAll(firstNameCol, lastNameCol); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); vbox.getChildren().addAll(table); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Callback<TableColumn<Person, String>, TableCell<Person, String>> cellFactory = ( TableColumn<Person, String> p) -> new EditingCell(); Scene scene = new Scene(new Group()); stage.setWidth(450);//from w ww . j av a2 s. c o m stage.setHeight(550); table.setEditable(true); TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name"); firstNameCol.setMinWidth(100); firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName")); firstNameCol.setCellFactory(cellFactory); firstNameCol.setOnEditCommit((CellEditEvent<Person, String> t) -> { ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setFirstName(t.getNewValue()); }); TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name"); lastNameCol.setMinWidth(100); lastNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName")); table.setItems(data); table.getColumns().addAll(firstNameCol, lastNameCol); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); vbox.getChildren().addAll(table); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.show(); }
From source file:com.github.douglasjunior.simpleCSVEditor.FXMLController.java
private TableColumn<CSVRow, String> createColumn(int index) { TableColumn<CSVRow, String> col = new TableColumn<>((index + 1) + ""); col.setSortable(false);//from w w w . ja v a 2 s . c om col.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<CSVRow, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(TableColumn.CellDataFeatures<CSVRow, String> param) { adjustColumns(param.getValue().getColumns()); return param.getValue().getColumns().get(index); } }); col.setCellFactory(TextFieldTableCell.forTableColumn()); col.setOnEditCommit(new EventHandler<CellEditEvent<CSVRow, String>>() { @Override public void handle(CellEditEvent<CSVRow, String> event) { adjustColumns(event.getRowValue().getColumns()); event.getRowValue().getColumns().get(index).set(event.getNewValue()); setNotSaved(); } }); col.setEditable(true); return col; }
From source file:ninja.javafx.smartcsv.fx.SmartCSVController.java
/** * Adds a column with the given name to the tableview * @param header name of the column header * @param tableView the tableview/* ww w . j av a 2 s.com*/ */ private void addColumn(final String header, TableView tableView) { TableColumn column = new TableColumn(header); column.setCellValueFactory(new ObservableMapValueFactory(header)); column.setCellFactory(cellFactory); column.setEditable(true); column.setSortable(false); ContextMenu contextMenu = contextMenuForColumn(header); column.setContextMenu(contextMenu); column.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<CSVRow, CSVValue>>() { @Override public void handle(TableColumn.CellEditEvent<CSVRow, CSVValue> event) { event.getTableView().getItems().get(event.getTablePosition().getRow()).getColumns().get(header) .setValue(event.getNewValue()); runLater(() -> { currentCsvFile.setFileChanged(true); }); } }); tableView.getColumns().add(column); }
From source file:memoryaid.SetReminderController.java
@FXML public void buildReminderTableData() throws SQLException { System.out.println("In builddata"); DbConnection db = new DbConnection(); Connection conn = db.connect(); String SQL = "select RId,ReminderName,ReminderType,StartDate,EndDate,ReminderTime from reminders"; ResultSet rs = conn.createStatement().executeQuery(SQL); TableColumn rIdCol = new TableColumn("RId"); rIdCol.setCellValueFactory(new PropertyValueFactory<>("reminderId")); TableColumn reminderNameCol = new TableColumn("ReminderName"); reminderNameCol.setCellValueFactory(new PropertyValueFactory<>("reminderName")); TableColumn reminderTypeCol = new TableColumn("ReminderType"); reminderTypeCol.setCellValueFactory(new PropertyValueFactory<>("reminderType")); TableColumn startDateCol = new TableColumn("StartDate"); startDateCol.setCellValueFactory(new PropertyValueFactory<>("startDate")); TableColumn endDateCol = new TableColumn("EndDate"); endDateCol.setCellValueFactory(new PropertyValueFactory<>("endDate")); TableColumn reminderTimeCol = new TableColumn("ReminderTime"); reminderTimeCol.setCellValueFactory(new PropertyValueFactory<>("reminderTime")); reminderTable.getColumns().add(rIdCol); reminderTable.getColumns().add(reminderNameCol); reminderTable.getColumns().add(reminderTypeCol); reminderTable.getColumns().add(startDateCol); reminderTable.getColumns().add(endDateCol); reminderTable.getColumns().add(reminderTimeCol); ObservableList<Object> data = FXCollections.observableArrayList(); while (rs.next()) { String rId = String.valueOf(rs.getInt("RId")); data.add(new ReminderModel(rId, rs.getString("ReminderName"), rs.getString("ReminderType"), rs.getString("StartDate"), rs.getString("EndDate"), rs.getString("ReminderTime"))); }/*from w w w . java2 s .co m*/ rs.close(); conn.close(); Callback<TableColumn<ReminderModel, String>, TableCell<ReminderModel, String>> cellFactory = ( TableColumn<ReminderModel, String> p) -> new EditingCell(); //Code For Reminder Name update reminderNameCol.setCellValueFactory(new PropertyValueFactory<>("reminderName")); reminderNameCol.setCellFactory(cellFactory); reminderNameCol.setOnEditCommit(new EventHandler<CellEditEvent<ReminderModel, String>>() { @Override public void handle(CellEditEvent<ReminderModel, String> t) { ((ReminderModel) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setReminderName(t.getNewValue()); System.out.println("*******" + t.getNewValue()); ReminderModel selectedItem = (ReminderModel) reminderTable.getSelectionModel().getSelectedItem(); System.out.println(selectedItem); String rIdToUpdate = selectedItem.getReminderId(); Statement stmt = null; DbConnection db = new DbConnection(); Connection conn = db.connect(); try { stmt = conn.createStatement(); String updateSql = "UPDATE Reminders set ReminderName = '" + t.getNewValue() + "'" + "WHERE RId = '" + rIdToUpdate + "'"; stmt.executeUpdate(updateSql); } catch (SQLException ex) { Logger.getLogger(SetReminderController.class.getName()).log(Level.SEVERE, null, ex); } } }); //For ReminderType Column Update reminderTypeCol.setCellValueFactory(new PropertyValueFactory<>("reminderType")); reminderTypeCol.setCellFactory(cellFactory); reminderTypeCol.setOnEditCommit(new EventHandler<CellEditEvent<ReminderModel, String>>() { @Override public void handle(CellEditEvent<ReminderModel, String> t) { ((ReminderModel) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setReminderType(t.getNewValue()); System.out.println("*******" + t.getNewValue()); ReminderModel selectedItem = (ReminderModel) reminderTable.getSelectionModel().getSelectedItem(); System.out.println(selectedItem); String rIdToUpdate = selectedItem.getReminderId(); Statement stmt = null; DbConnection db = new DbConnection(); Connection conn = db.connect(); try { stmt = conn.createStatement(); String updateSql = "UPDATE Reminders set ReminderType = '" + t.getNewValue() + "'" + "WHERE RId = '" + rIdToUpdate + "'"; stmt.executeUpdate(updateSql); } catch (SQLException ex) { Logger.getLogger(SetReminderController.class.getName()).log(Level.SEVERE, null, ex); } } }); //For reminderTime Column Update reminderTimeCol.setCellValueFactory(new PropertyValueFactory<>("reminderTime")); reminderTimeCol.setCellFactory(cellFactory); reminderTimeCol.setOnEditCommit(new EventHandler<CellEditEvent<ReminderModel, String>>() { @Override public void handle(CellEditEvent<ReminderModel, String> t) { ((ReminderModel) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setReminderTime(t.getNewValue()); System.out.println("*******" + t.getNewValue()); ReminderModel selectedItem = (ReminderModel) reminderTable.getSelectionModel().getSelectedItem(); System.out.println(selectedItem); String rIdToUpdate = selectedItem.getReminderId(); Statement stmt = null; DbConnection db = new DbConnection(); Connection conn = db.connect(); try { stmt = conn.createStatement(); String updateSql = "UPDATE Reminders set ReminderTime = '" + t.getNewValue() + "'" + "WHERE RId = '" + rIdToUpdate + "'"; stmt.executeUpdate(updateSql); } catch (SQLException ex) { Logger.getLogger(SetReminderController.class.getName()).log(Level.SEVERE, null, ex); } } }); reminderTable.setItems(data); }
From source file:dtv.controller.FXMLMainController.java
public void init(ObservableList<DVBChannel> serviceData, TableView<DVBChannel> table, TableColumn<DVBChannel, Integer> idx, TableColumn<DVBChannel, String> name, TableColumn<DVBChannel, String> type, TableColumn<DVBChannel, String> ppr) { table.setEditable(true);//from w w w .ja v a 2 s . c o m idx.setCellValueFactory(cellData -> cellData.getValue().idxProperty().asObject()); name.setCellValueFactory(cellData -> cellData.getValue().nameProperty()); name.setEditable(true); type.setCellValueFactory(cellData -> cellData.getValue().typeProperty()); // nid.setCellValueFactory(cellData -> cellData.getValue().nidProperty().asObject()); ppr.setCellValueFactory(cellData -> cellData.getValue().pprProperty()); // newCol.setCellValueFactory(cellData -> cellData.getValue().neewProperty()); // Context menu table.setRowFactory(tableView -> { final TableRow<DVBChannel> row = new TableRow<>(); final ContextMenu rowMenu = new ContextMenu(); final MenuItem removeItem = new MenuItem("Delete"); removeItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { final DVBChannel service = row.getItem(); serviceData.removeAll(service); } }); rowMenu.getItems().addAll(removeItem); row.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(row.itemProperty())).then(rowMenu) .otherwise((ContextMenu) null)); return row; }); ppr.setCellFactory(col -> { final TableCell<DVBChannel, String> cell = new TableCell<>(); cell.textProperty().bind(cell.itemProperty()); cell.itemProperty().addListener((obs, oldValue, newValue) -> { if (newValue != null) { final ContextMenu cellMenu = new ContextMenu(); for (String pref : Utils.prefTab) { final CheckMenuItem prefMenuItem = new CheckMenuItem(pref); if (Utils.isPreferenceOn(cell.getText(), pref)) { prefMenuItem.setSelected(true); } prefMenuItem.selectedProperty().addListener((obs1, old_val, new_val) -> { final String new_ppr; final DVBChannel service = (DVBChannel) cell.getTableRow().getItem(); if (new_val) { new_ppr = Utils.add_ppr(cell.getText(), pref); } else { new_ppr = Utils.remove_ppr(cell.getText(), pref); } service.setPpr(new_ppr); service.setModified(true); }); cellMenu.getItems().add(prefMenuItem); cell.setContextMenu(cellMenu); } } else { cell.setContextMenu(null); } }); return cell; }); // Editable service name name.setCellFactory(p -> new EditingCell()); name.setOnEditCommit(t -> { final DVBChannel service = t.getTableView().getItems().get(t.getTablePosition().getRow()); service.setName(t.getNewValue()); service.setModified(true); }); }
From source file:org.pdfsam.ui.selection.multiple.PaceColumn.java
@Override public TableColumn<SelectionTableRowData, String> getTableColumn() { TableColumn<SelectionTableRowData, String> tableColumn = SelectionTableColumn.super.getTableColumn(); tableColumn.setEditable(true);//from w ww. j ava 2 s . c o m tableColumn.setOnEditCommit(t -> t.getTableView().getItems().get(t.getTablePosition().getRow()).pace .set(defaultIfBlank(t.getNewValue(), "1"))); return tableColumn; }
From source file:org.pdfsam.ui.selection.multiple.PageRangesColumn.java
@Override public TableColumn<SelectionTableRowData, String> getTableColumn() { TableColumn<SelectionTableRowData, String> tableColumn = SelectionTableColumn.super.getTableColumn(); tableColumn.setEditable(true);/*from w ww.j a v a 2 s. c om*/ tableColumn .setOnEditCommit(t -> t.getTableView().getItems().get(t.getTablePosition().getRow()).pageSelection .set(t.getNewValue())); return tableColumn; }