Me ajudem em um evento para popular formulario JAVAFX

1 resposta
IsaelCoelho

bom dia!!

Estou com um problema para navegar em uma list onde pego os dados de uma entidade e populo o mesmo e quando tento fazer o sistema apenas mostra o ultimo registro, gostaria que alguem me ajudasse.

segue o laço que fis:

`@FXML

protected void TesteList(ActionEvent event) {

int a = dao.Listar().size();

int i = 1;

List fun = dao.Listar();

while (i <= a) {
// JOptionPane.showMessageDialog(null, fun.get(i).getNome());

        txtNome.setText(fun.get(i).getNome());
        i=i+1;
    }
}`

o erro que esta mostrando é

Exception in thread JavaFX Application Thread java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)

at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)

at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)

at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)

at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)

at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)

at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)

at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)

at javafx.event.Event.fireEvent(Unknown Source)

at javafx.scene.Node.fireEvent(Unknown Source)

at javafx.scene.control.Button.fire(Unknown Source)

at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)

at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)

at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)

at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)

at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)

at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)

at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)

at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)

at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)

at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)

at javafx.event.Event.fireEvent(Unknown Source)

at javafx.scene.Scene$MouseHandler.process(Unknown Source)

at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)

at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)

at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)

at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)

at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)

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

at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(Unknown Source)

at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)

at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)

at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)

at com.sun.glass.ui.View.notifyMouse(Unknown Source)

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

at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)

at java.lang.Thread.run(Unknown Source)

1 Resposta

pcollares

O Javafx é ‘thread safe’, isso significa que toda alteração de interface do javafx deve ser feito na thread do fx, para isso coloque o seu evento de modificação de interface, neste caso o setText dentro desta chamada da thread do fx usando lambdas:

Platform.runLater(() -> {
        txtNome.setText(fun.get(i).getNome());
});
Criado 26 de abril de 2016
Ultima resposta 27 de abr. de 2016
Respostas 1
Participantes 2