I am trying to put a stack panel in my TableView
and I keep getting errors.
I suspect it is my lack of understanding of creating the Cell Value Factory.
My Code looks like:
TableColumn obj = new TableColumn("Func " + i);
final int index = i;
obj.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ObservableList<String>, String>, TableCell<ObservableList<String>, String>>() {
@Override
public TableCell<ObservableList<String>, String> call(final CellDataFeatures<ObservableList<String>, String> cdf) {
if (index + 2 >= cdf.getValue().size()) {
return null;
}
//return new SimpleStringProperty(cdf.getValue().get(index + 2));
return new TableCell<ObservableList<String>, String>(){
Label funcLbl = new Label(cdf.getValue().get(index+2));
StackPane sp = new StackPane();
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty); //To change body of generated methods, choose Tools | Templates.
sp.getChildren().add(funcLbl);
setGraphic(sp);
}
};
}
});
obj.setMinWidth(100);
this.getColumns().add(obj);
And the Error I am getting is
SEVERE: javafx.scene.control.Control loadSkinClass Failed to load skin 'StringProperty [bean: PinTable[id=null, styleClass=table-view], name: skinClassName, value: com.sun.javafx.scene.control.skin.TableViewSkin]' for control PinTable[id=null, styleClass=table-view]
java.lang.ClassCastException: mapr.components.mainui.render.table.MyTable$3$1 cannot be cast to javafx.beans.value.ObservableValue
at javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:1209)
at javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:1179)
at javafx.scene.control.TableCell.updateItem(TableCell.java:543)
at javafx.scene.control.TableCell.indexChanged(TableCell.java:105)
at javafx.scene.control.TableCell$1.invalidated(TableCell.java:93)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:155)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
at javafx.beans.property.ReadOnlyIntegerWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:195)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:161)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:130)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:163)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:112)
at com.sun.javafx.scene.control.skin.TableColumnHeader.resizeToFit(TableColumnHeader.java:619)
at com.sun.javafx.scene.control.skin.TableColumnHeader$1.invalidated(TableColumnHeader.java:138)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:155)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
at javafx.beans.property.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:195)
at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:161)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:130)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
at javafx.scene.Node.setScene(Node.java:661)
at javafx.scene.Parent.computeDirtyScene(Parent.java:599)
at javafx.scene.Parent.sceneChanged(Parent.java:612)
at javafx.scene.Node$4.invalidated(Node.java:699)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:129)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
at javafx.scene.Node.setScene(Node.java:661)
at javafx.scene.Parent.computeDirtyScene(Parent.java:599)
at javafx.scene.Parent.sceneChanged(Parent.java:612)
at javafx.scene.Node$4.invalidated(Node.java:699)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:129)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
at javafx.scene.Node.setScene(Node.java:661)
at javafx.scene.Parent.computeDirtyScene(Parent.java:599)
at javafx.scene.Parent.sceneChanged(Parent.java:612)
at javafx.scene.Node$4.invalidated(Node.java:699)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:129)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
at javafx.scene.Node.setScene(Node.java:661)
at javafx.scene.Parent$1.onChanged(Parent.java:425)
at com.sun.javafx.collections.VetoableObservableList.callObservers(VetoableObservableList.java:83)
at com.sun.javafx.collections.ObservableListWrapper.setAll(ObservableListWrapper.java:303)
at com.sun.javafx.collections.VetoableObservableList.setAll(VetoableObservableList.java:92)
at com.sun.javafx.collections.ObservableListWrapper.setAll(ObservableListWrapper.java:314)
at javafx.scene.control.Control.updateChildren(Control.java:947)
at javafx.scene.control.Control.access$100(Control.java:70)
at javafx.scene.control.Control$1.invalidated(Control.java:207)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:129)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
at com.sun.javafx.css.StyleableObjectProperty.set(StyleableObjectProperty.java:70)
at javafx.scene.control.Control$1.set(Control.java:186)
at javafx.scene.control.Control$1.set(Control.java:171)
at javafx.scene.control.Control.loadSkinClass(Control.java:1047)
at javafx.scene.control.Control.access$500(Control.java:70)
at javafx.scene.control.Control$12.invalidated(Control.java:972)
at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:127)
at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:161)
at com.sun.javafx.css.StyleableStringProperty.set(StyleableStringProperty.java:71)
at javafx.scene.control.Control$12.set(Control.java:964)
at com.sun.javafx.css.StyleableStringProperty.applyStyle(StyleableStringProperty.java:59)
at com.sun.javafx.css.StyleableStringProperty.applyStyle(StyleableStringProperty.java:31)
at com.sun.javafx.css.StyleableProperty.set(StyleableProperty.java:70)
at com.sun.javafx.css.StyleHelper.transitionToState(StyleHelper.java:902)
at javafx.scene.Node.impl_processCSS(Node.java:7415)
at javafx.scene.Parent.impl_processCSS(Parent.java:1146)
at javafx.scene.control.Control.impl_processCSS(Control.java:1154)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.control.Control.impl_processCSS(Control.java:1154)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.control.Control.impl_processCSS(Control.java:1154)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Node.processCSS(Node.java:7383)
at javafx.scene.Node.processCSS(Node.java:7377)
at javafx.scene.Node.processCSS(Node.java:7377)
at javafx.scene.Scene.doCSSPass(Scene.java:446)
at javafx.scene.Scene.access$3800(Scene.java:170)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2202)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:363)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:460)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:329)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:724)
I am trying to convert from using a
public ObservableValue<String> call(CellDataFeatures<ObservableList<String>, String> cdf)
and only returning a SimpleStringProperty
to returning a TableCell<ObservableList<String>
, String> that has a StackPane
as its content with the String
held in a Label
(I want to create actions based on clicking on the stack pane).
Any help on understanding the transition would be great!
CellValueFactory is to populate data in cells of column from model object ..
Example :
lastNameCol.setCellValueFactory(new PropertyValueFactory<Person,String>("lastName"));
If you want to render data in all cells of table column then you must use cellFactory .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.