Ich habe mir ein Textfeld individualisiert, hier für Prüfung Integer.
Das hat beim letzten verwenden auch einwandfrei funktioniert.
Heute habe ich den ganzen Tag damit verbracht nach der Ursache zu suchen warum es jetzt nicht mehr läuft.
In der Fehlermeldung wird von einer Unmöglichkeit berichtet einen Integer in einen String umzuwandeln.
Das verstehe ich überhaupt nicht, man kann doch so ziemlich alles in einen String umwandeln.
Ich komm da nicht mehr weiter.
Hier mal die Fehlermeldung.
hier dann mein Aufruf
hier die Datenklasse
und meine CellClass
Ich muss das noch mal erwähnen, das hat alles schon mal einwandfrei gelaufen.
Aber ich finde die Fehlerursache nicht.
Das hat beim letzten verwenden auch einwandfrei funktioniert.
Heute habe ich den ganzen Tag damit verbracht nach der Ursache zu suchen warum es jetzt nicht mehr läuft.
In der Fehlermeldung wird von einer Unmöglichkeit berichtet einen Integer in einen String umzuwandeln.
Das verstehe ich überhaupt nicht, man kann doch so ziemlich alles in einen String umwandeln.
Ich komm da nicht mehr weiter.
Hier mal die Fehlermeldung.
Java:
Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap')
at org.joobsoft.vt.SYS.CELLCLASSES.CellClassTextFieldInteger.updateItem(CellClassTextFieldInteger.java:21)
at javafx.controls/javafx.scene.control.TableCell.updateItem(TableCell.java:665)
at javafx.controls/javafx.scene.control.TableCell.indexChanged(TableCell.java:469)
at javafx.controls/javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:120)
at javafx.controls/javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:539)
at javafx.controls/javafx.scene.control.skin.TableRowSkinBase.<init>(TableRowSkinBase.java:159)
at javafx.controls/javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:89)
at javafx.controls/javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:213)
at javafx.controls/javafx.scene.control.Control.doProcessCSS(Control.java:897)
at javafx.controls/javafx.scene.control.Control$1.doProcessCSS(Control.java:89)
at javafx.controls/com.sun.javafx.scene.control.ControlHelper.processCSSImpl(ControlHelper.java:67)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:145)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9542)
at javafx.graphics/javafx.scene.Node.applyCss(Node.java:9629)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1749)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1726)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1852)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.computeViewportOffset(VirtualFlow.java:2755)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1245)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1207)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
at javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)
at javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:1784)
at javafx.graphics/javafx.scene.Scene$2.preferredSize(Scene.java:393)
at javafx.graphics/com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)
at javafx.graphics/javafx.stage.Window$12.invalidated(Window.java:1086)
at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
at javafx.base/javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
at javafx.graphics/javafx.stage.Window.setShowing(Window.java:1174)
at javafx.graphics/javafx.stage.Window.show(Window.java:1189)
at javafx.graphics/javafx.stage.Stage.show(Stage.java:273)
at org.joobsoft.vt.APP.CONTROLLER.PVA00000.HomeworkListController.openConfigWindow(HomeworkListController.java:713)
at org.joobsoft.vt.APP.CONTROLLER.PVA00000.HomeworkListController$2.lambda$new$0(HomeworkListController.java:222)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8885)
at javafx.controls/javafx.scene.control.Button.fire(Button.java:203)
at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3890)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1885)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2618)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:832)
hier dann mein Aufruf
Java:
@FXML private TableColumn<DataHomeworkGroup,String> colPercent;
colPercent.setText(getlangstring("Class.HWGroups.colheader.percent"));
colPercent.setCellValueFactory(new PropertyValueFactory<>("RatedPercent"));
colPercent.setCellFactory(i -> new CellClassTextFieldInteger(colPercent, 0, 100, 100));
colPercent.setOnEditCommit(e -> { percRightCheckSafe(e); });
hier die Datenklasse
Java:
public class DataHomeworkGroup implements Cloneable{
private String id;
private String idHw;
private String groupName;
private boolean rated;
private LocalDate rateDate;
private Integer ratedPercent;
private String ratedGrade;
private String objection;
public DataHomeworkGroup( String strid,
String stridhw,
String strgroupname,
boolean boorated,
LocalDate strratedate,
String strratedpercent,
String strratedgrade,
String objection) {
this.id = strid;
this.idHw = stridhw;
this.groupName = strgroupname;
this.rated = boorated;
this.rateDate = strratedate;
this.ratedPercent = Integer.valueOf(strratedpercent);
this.ratedGrade = strratedgrade;
this.objection = objection;
}
public DataHomeworkGroup() {}
@Override
public Object clone() {
try { return super.clone();
} catch (CloneNotSupportedException ex) { Logger.getLogger(DataHomeworkGroup.class.getName()).log(Level.WARNING, ex.getMessage(), ex); }
return new DataHomeworkGroup();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getIdHw() {
return idHw;
}
public void setIdHw(String idHw) {
this.idHw = idHw;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public boolean getRated() {
return rated;
}
public void setRated(boolean rated) {
this.rated = rated;
}
public LocalDate getRateDate() {
return rateDate;
}
public void setRateDate(LocalDate rateDate) {
this.rateDate = rateDate;
}
public Integer getRatedPercent() {
return ratedPercent;
}
public void setRatedPercent(Integer ratedPercent) {
this.ratedPercent = ratedPercent;
}
public String getRatedGrade() {
return ratedGrade;
}
public void setRatedGrade(String ratedGrade) {
this.ratedGrade = ratedGrade;
}
public String getObjection() {
return objection;
}
public void setObjection(String objection) {
this.objection = objection;
}
}
und meine CellClass
Java:
public class CellClassTextFieldInteger<T,S> extends TableCell<T, String>
{
private TextField textField;
private final int maxValue;
private final int minValue;
private final int defaultValue;
private final TableColumn tfCol;
private final TableView tableView;
public CellClassTextFieldInteger(TableColumn<T, String> stringCol, int minValue, int maxValue, int defaultValue)
{
this.maxValue = maxValue;
this.minValue = minValue;
this.defaultValue = defaultValue;
this.tfCol = stringCol;
this.tableView = tfCol.getTableView();
}
protected void updateItem(String strInput, boolean empty) {
super.updateItem(strInput, empty);
if (empty)
{
setText(null);
setGraphic(null);
} else
{
if (isEditing())
{
if (textField != null)
{
textField.setText(getString());
}
setGraphic(textField);
} else
{
setText(getString());
setGraphic(null);
}
}
}
@Override
public final void cancelEdit()
{
super.cancelEdit();
}
@Override
public final void commitEdit(final String newValue)
{
super.commitEdit(newValue);
}
@Override
public final void startEdit()
{
super.startEdit();
if (textField == null) { createTextfield(); }
setGraphic(textField);
textField.setText(getString());
textField.selectAll();
textField.requestFocus();
}
private void createTextfield () {
this.textField = new TextField();
this.textField.setTextFormatter(new TextFormatter<>(new StringConverter<Integer>() {
@Override
public String toString(Integer object) {
return object != 0 ? String.valueOf(object) : String.valueOf(defaultValue);
}
@Override
public Integer fromString(String string) {
try {
int userInput = Integer.valueOf(string);
if (userInput > maxValue) {userInput = maxValue;}
if (userInput < minValue) {userInput = minValue;}
return userInput;
} catch (NumberFormatException ex) {
Toolkit.getDefaultToolkit().beep();
return defaultValue;
}
}
}));
// Bind this cells editable property to the whole Column
editableProperty().bind(tfCol.editableProperty());
// configure TextField, sonst schreibt fx zwei mal sieht dann aus wie eine zweite Spalte
contentDisplayProperty().bind(Bindings
.when(editableProperty())
.then(ContentDisplay.GRAPHIC_ONLY)
.otherwise(ContentDisplay.TEXT_ONLY)
);
setListener () ;
}
private void setListener () {
this.textField.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(oldValue)
{
try
{
Integer checkValue = Integer.valueOf(textField.getText());
if (checkValue > maxValue)
{
Toolkit.getDefaultToolkit().beep();
textField.setText(String.valueOf(maxValue));
}
if (checkValue < minValue)
{
Toolkit.getDefaultToolkit().beep();
textField.setText(String.valueOf(minValue));
}
} catch (NumberFormatException ex)
{
Toolkit.getDefaultToolkit().beep();
textField.setText(String.valueOf(defaultValue));
}
commitEdit(textField.getText());
CellEditEvent<T,S> event = new CellEditEvent<>(tableView,
new TablePosition<>(tableView,
getIndex(),
tfCol),
TableColumn.editCommitEvent(),
textField.getText());
Event.fireEvent(tfCol, event);
} else
{
textField.selectAll();
}
});
this.textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override public void handle(KeyEvent evt) {
if (KeyCode.ESCAPE == evt.getCode())
{
cancelEdit();
}
if (KeyCode.ENTER == evt.getCode() || KeyCode.TAB == evt.getCode() )
{
commitEdit(textField.getText());
}
}
});
}
private String getString()
{
return getItem() == null ? "-" : getItem().toString();
}
Ich muss das noch mal erwähnen, das hat alles schon mal einwandfrei gelaufen.
Aber ich finde die Fehlerursache nicht.