[英]Populating TableView In JavaFX with TableView created in FXML File
[英]JavaFX: TableView couldn't edit with FXML
我目前正在使用包含TableView
FXML开发JavaFX应用程序。 我不知道如何在TextFieldTableCell<S,T>
使用StringConverter<T>
TextFieldTableCell<S,T>
。 到目前为止,我已经完成了一些代码。 当texfield值保存到单元格时,它返回Exception;
这是我的来源...
@FXML
private TableColumn<Customer, Integer> columnID;
columnID.setCellFactory(
new Callback<TableColumn<Customer, Integer>, TableCell<Customer, Integer>>() {
StringConverter<Integer> converter;
@Override
public TableCell<Customer, Integer> call(TableColumn<Customer, Integer> list) {
return new TextFieldTableCell<>(converter);
}
}
);
它返回此异常...
Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Attempting to convert text input into Object, but provided StringConverter is null. Be sure to set a StringConverter in your cell factory.
at javafx.scene.control.cell.CellUtils$4.handle(CellUtils.java:247)
at javafx.scene.control.cell.CellUtils$4.handle(CellUtils.java:243)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:204)
at javafx.scene.Scene$KeyHandler.process(Scene.java:3949)
at javafx.scene.Scene$KeyHandler.access$2100(Scene.java:3896)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2036)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2493)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:170)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:123)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:197)
at com.sun.glass.ui.View.handleKeyEvent(View.java:517)
at com.sun.glass.ui.View.notifyKey(View.java:927)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
at java.lang.Thread.run(Thread.java:744)
我找到了解决方案。 这是我的解决方案...
columnID.setCellFactory(
new Callback<TableColumn<Customer, Integer>, TableCell<Customer, Integer>>() {
StringConverter<Integer> converter;
@Override
public TableCell<Customer, Integer> call(TableColumn<Customer, Integer> list) {
return new TextFieldTableCell(new NumberStringConverter());
}
}
);
另一个简单的解决方案
columnID.setCellFactory(TextFieldTableCell.forTableColumn());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.