您的事件处理程序类型对我来说不错。我的猜测是类型不匹配正在其他地方发生。
样品
这是一个示例,演示了使用FXML时如何设置提交事件处理程序。为冗长而道歉,这就是FXML的方式。
该示例中的编辑提交处理程序为:
@FXMLvoid commitValue(TableColumn.CellEditEvent<Singular, String> event) { System.out.println("Commit: " + event.getNewValue());}其中Singluar只是该示例在TableView中使用的记录类的名称。
commit / CommitController.java
import javafx.beans.property.SimpleStringProperty;import javafx.beans.property.StringProperty;import javafx.fxml.FXML;import javafx.scene.control.TableColumn;import javafx.scene.control.TableView;import javafx.scene.control.cell.PropertyValueFactory;import javafx.scene.control.cell.TextFieldTableCell;public class CommitController { @FXML private TableView<Singular> table; @FXML private TableColumn<Singular, String> value; @FXML void commitValue(TableColumn.CellEditEvent<Singular, String> event) { System.out.println("Commit: " + event.getNewValue()); } public void initialize() { value.setCellFactory(TextFieldTableCell.forTableColumn()); value.setCellValueFactory(new PropertyValueFactory<>("value")); value.setEditable(true); table.getItems().setAll( new Singular("enie"), new Singular("meenie"), new Singular("minie"), new Singular("moe"), new Singular("just commit!") ); table.setEditable(true); } public static class Singular { private StringProperty value = new SimpleStringProperty(); public Singular(String value) { this.value.setValue(value); } public StringProperty valueProperty() { return value; } }}commit / CommitmentApp.java
import javafx.application.Application;import javafx.fxml.FXMLLoader;import javafx.scene.Parent;import javafx.scene.Scene;import javafx.stage.Stage;import java.io.IOException;public class CommitmentApp extends Application { @Override public void start(Stage stage) throws IOException { stage.setScene(new Scene(createContent())); stage.show(); } private Parent createContent() throws IOException { FXMLLoader loader = new FXMLLoader(); return loader.load( getClass().getResourceAsStream("commit.fxml") ); } public static void main(String[] args) { launch(args); }}commit.fxml
<?import javafx.scene.control.TableColumn?><?import javafx.scene.control.TableView?><TableView fx:id="table" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="130.0" prefWidth="113.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="commit.CommitController"> <columns> <TableColumn fx:id="value" onEditCommit="#commitValue" prefWidth="85.0" text="C1" /> </columns></TableView>



