Tasks unter JavaFX

MS-Tech

Erfahrenes Mitglied
Hallo Zusammen,

ich habe eine abstrakte Klasse gebaut, die von der Klasse Task abgeleitet ist. Ich möchte in der Klasse einen Dialgo mit einer ProgressBar anzeigen. Der Dialog selber wird angezeigt, jedoch wird die Methode succeeded nicht aufgerufen, weil vorher eine Exception fliegt. Ich weis da garade nicht mehr weiter, hat jemand ne Idee????

Java:
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public abstract class WorkingTask extends Task<Void> {

    private ProgressBar progress = null;
    private Label updateLabel = null;
    private Stage taskUpdateStage = null;

    protected abstract void work() throws Exception;

    @Override
    protected Void call() throws Exception {
        try {
            work();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javafx.concurrent.Task#succeeded()
     */
    @Override
    protected void succeeded() {
        taskUpdateStage.close();
    }

    public void startWorkingTask() throws Exception {
        initMonitor();
        start();
    }

    private void initMonitor() {
        final double wndwWidth = 300.0d;
        updateLabel = new Label("Bitte haben Sie einen Augenblick Gedult...");
        updateLabel.setPrefWidth(wndwWidth);
        progress = new ProgressBar(ProgressBar.INDETERMINATE_PROGRESS);
        progress.setPrefWidth(wndwWidth);

        VBox updatePane = new VBox();
        updatePane.setPadding(new Insets(10));
        updatePane.setSpacing(5.0d);
        updatePane.getChildren().addAll(updateLabel, progress);

        taskUpdateStage = new Stage(StageStyle.UTILITY);
        taskUpdateStage.setScene(new Scene(updatePane));
    }

    private void start() {
        taskUpdateStage.show();
        new Thread(this).start();
    }
}

Exception:

Java:
java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-7
    at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
    at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
    at javafx.scene.Parent$2.onProposedChange(Parent.java:367)
    at com.sun.javafx.collections.VetoableListDecorator.clear(VetoableListDecorator.java:294)

Grüße
MS-Tech
 

Neue Beiträge

Zurück