帮助我了解折线图以及如何做得更好。 我需要添加折线图2-3时间表30 - 从数据库到达的值。我想制作一个单独的流,但是有错误。
错误:'线程中的异常“Thread-4” java.lang.IllegalStateException:不在FX应用程序线程上; currentThread = Thread-4''
import extfx.scene.chart.DateAxis;
import javafx.application.Application;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.util.Date;
import java.util.GregorianCalendar;
public class main extends Application{
public static void main(String[] args) {
launch(args);
}
public static LineChart<Date, Number> lineChart;
public static Thread threadInTrendFlow;
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("-----------------------");
NumberAxis numberAxis = new NumberAxis();
DateAxis dateAxis = new DateAxis();
lineChart = new LineChart<Date, Number>(dateAxis,numberAxis);
lineChart.getData().add(scFlow.series);
BorderPane pane = new BorderPane();
pane.setCenter(lineChart);
///
Button inLineChart = new Button("insert");
inLineChart.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Task<Void> loaded = new scFlow();
threadInTrendFlow = new Thread(loaded);
threadInTrendFlow.start();
}
});
pane.setTop(inLineChart);
Scene scene = new Scene(pane,800,600);
primaryStage.setScene(scene);
primaryStage.show();
}
}
答案 0 :(得分:0)
在调用应用程序线程中的内容时使用Platform.runlater(() - &gt; {})。
有很多线程与某些类似的问题有关。只需搜索多线程javafx。