Como gerar uma TreeTableView?

2 respostas
programaçãojavafxjava
M

preciso criar uma lista de contatos onde seja agrupada de acordo a data

a model é essa
public class listanomes {

private Calendar data;

private TabNome nomeum;

private Double valor;

private TabNome nomedois;


e eu estou fazendo assim para puxar, porem não da certo

TreeItem root = new TreeItem(b.getDatmovi());

teste = new TreeTableView<>(root);

teste.setShowRoot(true);
TreeTableColumn nome= new TreeTableColumn("Nome um");
    ctncred.setCellFactory(new Callback() {
        @Override
        public Object call(Object param) {
            
            Object nomeum= ((TreeTableColumn.CellDataFeatures) param) .getValue ().getValue();
if (nomeum instanceof listanomes ) {

return new ReadOnlyStringWrapper (String.valueOf (((listanomes ) nomeum ).getNomeUm()));

}

else if (nomeum instanceof listanomes ) {

return “”;

}

return null;

}

});
List <listanomes > tist = new listacontabeisDao().finaltr(b.getDatmovi().getTime());
tist.stream ().forEach((e) -> {

final TreeItem tTreeItem = new TreeItem (e);

root.getChildren ().add(tTreeItem );

tTreeItem .getChildren ().add(e.getNomeUm().getNome());

});

teste.getColumns().setAll(nome);
    System.out.println("");

2 Respostas

j-menezes

https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/tree-table-view.htm

M

utilizei essa mesmo, mas ta dando erro , adaptei pro meu caso e o erro é o seguinte

Exception in thread JavaFX Application Thread java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.control.TreeItem

at javafx.scene.control.TreeItem.updateChildrenParent(TreeItem.java:928)

at javafx.scene.control.TreeItem.updateChildren(TreeItem.java:914)

at javafx.scene.control.TreeItem.lambda$new$113(TreeItem.java:412)

at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)

at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)

at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)

at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)

at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)

at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)

at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)

at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)

at br.inf.topsoft.contabeis.controller.FormCadLanc.lambda$updateDados$8(FormCadLanc.java:529)

at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)

at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)

at br.inf.topsoft.contabeis.controller.FormCadLanc.updateDados(FormCadLanc.java:525)

at br.inf.topsoft.contabeis.controller.FormCadLanc.carregarDados(FormCadLanc.java:248)

at br.inf.topsoft.contabeis.controller.FormCadLanc.onLoad(FormCadLanc.java:184)

at br.inf.topsoft.jtopdevfx.forms.TopFxCadTabController$2$1.lambda$call$0(TopFxCadTabController.java:232)

at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)

at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)

at java.lang.Thread.run(Thread.java:745)

Exception in thread JavaFX Application Thread java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.control.TreeItem

at javafx.scene.control.TreeItem.updateChildrenParent(TreeItem.java:928)

at javafx.scene.control.TreeItem.updateChildren(TreeItem.java:914)

Apareça: JOSE EDILON

at javafx.scene.control.TreeItem.lambda$new$113(TreeItem.java:412)

at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)

at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)

at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)

at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)

at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)

at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)

at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)

at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)

at br.inf.topsoft.contabeis.controller.FormCadLanc.lambda$updateDados$8(FormCadLanc.java:529)

at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)

at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)

at br.inf.topsoft.contabeis.controller.FormCadLanc.updateDados(FormCadLanc.java:525)

at br.inf.topsoft.contabeis.controller.FormCadLanc.carregarDados(FormCadLanc.java:248)

at br.inf.topsoft.contabeis.controller.FormCadLanc.onLoad(FormCadLanc.java:184)

at br.inf.topsoft.jtopdevfx.forms.TopFxCadTabController$2$1.lambda$call$0(TopFxCadTabController.java:232)

at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)

at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)

at java.lang.Thread.run(Thread.java:745)

Exception in thread JavaFX Application Thread java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.control.TreeItem

at javafx.scene.control.TreeItem.updateChildrenParent(TreeItem.java:928)

at javafx.scene.control.TreeItem.updateChildren(TreeItem.java:914)

at javafx.scene.control.TreeItem.lambda$new$113(TreeItem.java:412)

at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)

at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)

at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)

at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)

at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)

at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)

at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)

at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)

at br.inf.topsoft.contabeis.controller.FormCadLanc.lambda$updateDados$8(FormCadLanc.java:529)

at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)

at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)

at br.inf.topsoft.contabeis.controller.FormCadLanc.updateDados(FormCadLanc.java:525)

at br.inf.topsoft.contabeis.controller.FormCadLanc.carregarDados(FormCadLanc.java:248)

at br.inf.topsoft.contabeis.controller.FormCadLanc.onLoad(FormCadLanc.java:184)

at br.inf.topsoft.jtopdevfx.forms.TopFxCadTabController$2$1.lambda$call$0(TopFxCadTabController.java:232)

at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)

at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)

at java.lang.Thread.run(Thread.java:745)

Exception in thread JavaFX Application Thread java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.control.TreeItem

at javafx.scene.control.TreeItem.updateChildrenParent(TreeItem.java:928)

at javafx.scene.control.TreeItem.updateChildren(TreeItem.java:914)

at javafx.scene.control.TreeItem.lambda$new$113(TreeItem.java:412)

at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)

at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)

at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)

at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)

at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)

at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)

at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)

at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)

at br.inf.topsoft.contabeis.controller.FormCadLanc.lambda$updateDados$8(FormCadLanc.java:529)

at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)

at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)

at br.inf.topsoft.contabeis.controller.FormCadLanc.updateDados(FormCadLanc.java:525)

at br.inf.topsoft.contabeis.controller.FormCadLanc.carregarDados(FormCadLanc.java:248)

at br.inf.topsoft.contabeis.controller.FormCadLanc.onLoad(FormCadLanc.java:184)

at br.inf.topsoft.jtopdevfx.forms.TopFxCadTabController$2$1.lambda$call$0(TopFxCadTabController.java:232)

at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)

at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)

at java.lang.Thread.run(Thread.java:745)

Exception in thread JavaFX Application Thread java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.control.TreeItem

at javafx.scene.control.TreeItem.updateChildrenParent(TreeItem.java:928)

at javafx.scene.control.TreeItem.updateChildren(TreeItem.java:914)

at javafx.scene.control.TreeItem.lambda$new$113(TreeItem.java:412)

at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)

at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)

at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)

at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)

at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)

at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)

at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)

at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)

at br.inf.topsoft.contabeis.controller.FormCadLanc.lambda$updateDados$8(FormCadLanc.java:529)

at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)

at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)

at br.inf.topsoft.contabeis.controller.FormCadLanc.updateDados(FormCadLanc.java:525)

at br.inf.topsoft.contabeis.controller.FormCadLanc.carregarDados(FormCadLanc.java:248)

at br.inf.topsoft.contabeis.controller.FormCadLanc.onLoad(FormCadLanc.java:184)

at br.inf.topsoft.jtopdevfx.forms.TopFxCadTabController$2$1.lambda$call$0(TopFxCadTabController.java:232)

at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)

at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)

at java.lang.Thread.run(Thread.java:745)

Exception in thread JavaFX Application Thread java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.control.TreeItem

at javafx.scene.control.TreeItem.updateChildrenParent(TreeItem.java:928)

at javafx.scene.control.TreeItem.updateChildren(TreeItem.java:914)
at javafx.scene.control.TreeItem.lambda$new$113(TreeItem.java:412)
at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)
at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)
at br.inf.topsoft.contabeis.controller.FormCadLanc.lambda$updateDados$8(FormCadLanc.java:529)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at br.inf.topsoft.contabeis.controller.FormCadLanc.updateDados(FormCadLanc.java:525)
at br.inf.topsoft.contabeis.controller.FormCadLanc.carregarDados(FormCadLanc.java:248)
at br.inf.topsoft.contabeis.controller.FormCadLanc.onLoad(FormCadLanc.java:184)
at br.inf.topsoft.jtopdevfx.forms.TopFxCadTabController$2$1.lambda$call$0(TopFxCadTabController.java:232)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Exception in thread JavaFX Application Thread java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.control.TreeItem

at javafx.scene.control.TreeItem.updateChildrenParent(TreeItem.java:928)

at javafx.scene.control.TreeItem.updateChildren(TreeItem.java:914)

at javafx.scene.control.TreeItem.lambda$new$113(TreeItem.java:412)

at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)

at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)

at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)

at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)

at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)

at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)

at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)

at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)

at br.inf.topsoft.contabeis.controller.FormCadLanc.lambda$updateDados$8(FormCadLanc.java:529)

at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)

at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)

at br.inf.topsoft.contabeis.controller.FormCadLanc.updateDados(FormCadLanc.java:525)

at br.inf.topsoft.contabeis.controller.FormCadLanc.carregarDados(FormCadLanc.java:248)

at br.inf.topsoft.contabeis.controller.FormCadLanc.onLoad(FormCadLanc.java:184)

at br.inf.topsoft.jtopdevfx.forms.TopFxCadTabController$2$1.lambda$call$0(TopFxCadTabController.java:232)

at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)

at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)

at java.lang.Thread.run(Thread.java:745)
Criado 25 de maio de 2018
Ultima resposta 25 de mai. de 2018
Respostas 2
Participantes 2