Issue
I am creating a new window controller in which I process data to be put into a linechart.
Though in the end the new window shows an empty LineChart. When I debug the line in which the series is put into the Linechart, the IDE states "series[null]".
So what am I missing?
Class of the new window:
public class ChartWindow {
Map<Job, List<LoadTestResultStatus>> lTRSMapOfJobs;
final LineChart lineChartMain;
Job originJob;
XYChart.Series series;
boolean lTRSfilled=false;
ObjectHub objectHub;
public ChartWindow(Job job, ObjectHub objectHub) {
this.objectHub = objectHub;
series = new XYChart.Series();
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Time");
yAxis.setLabel("Time");
lineChartMain = new LineChart<Number, Number>(xAxis, yAxis);
lTRSMapOfJobs = new HashMap<>();
originJob = job;
lTRSMapOfJobs.put(job, objectHub.getDbManagement().getLTRSListOfJobFromDB(job));
fillLineChart();
}
public void fillLineChart() {
Platform.runLater(new Runnable() {
@Override
public void run() {
objectHub.getGuiReporter().statusStart(0);
objectHub.getGuiReporter().progressbarAddAmountOfStep(lTRSMapOfJobs.get(originJob).size());
}
});
for (LoadTestResultStatus l : lTRSMapOfJobs.get(originJob)) {
objectHub.getExecutor().submit(new Runnable() {
@Override
public void run() {
XYChart.Data xyChart = new XYChart.Data(l.getTs(), l.getLt());
try {
addToSeries(xyChart);
objectHub.getGuiReporter().progressbarAddStep();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//TODO heavy CPU load:(
while(!lTRSfilled){
if(ObjectHub.getGuiReporter().progressBarDifference()==0){
lTRSfilled = true;
}
}
lineChartMain.getData().addAll(series);
}
void addToSeries(XYChart.Data xyChart) {
synchronized (this) {
series.getData().add(xyChart);
}
}
public Map<Job, List<LoadTestResultStatus>> getlTRSMapOfJobs() {
return lTRSMapOfJobs;
}
public void setlTRSMapOfJobs(Map<Job, List<LoadTestResultStatus>> lTRSMapOfJobs) {
this.lTRSMapOfJobs = lTRSMapOfJobs;
}
public LineChart getLineChartMain() {
return lineChartMain;
}
}
MainController method who processes the new window:
public void showLineChartForJob() {
progressBarLabel.setText("Preparing Linechart calculation...");
ChartWindow object to request executorservices
Thread createChartWindow = new Thread(new Runnable() {
@Override
public void run() {
int jobId = Integer.parseInt(visualizeTabIdInputTextField.getText());
Job lineChartJob = new Job(objectHub);
for (Job j : objectHub.getLtResultManagement().getjobSet()) {
if (j.getNumber() == jobId) {
lineChartJob = j;
break;
}
}
chartWindowList.add(new ChartWindow(lineChartJob, objectHub));
Platform.runLater(new Runnable() {
@Override
public void run() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/ChartWindow.fxml"));
fxmlLoader.setController(chartWindowList.get(0));
StackPane secondaryLayout = new StackPane();
try {
secondaryLayout.getChildren().setAll(Collections.singleton(fxmlLoader.load()));
} catch (IOException e) {
e.printStackTrace();
}
Scene secondScene = new Scene(secondaryLayout, 1200, 1600);
Stage newWindow = new Stage();
newWindow.setTitle("Second Stage");
newWindow.setScene(secondScene);
newWindow.setX(50);
newWindow.setY(50);
newWindow.show();
}
});
}
});
createChartWindow.setName("createChartWindowThread");
createChartWindow.start();
}
Capture from debug taken at the last line of the First Controller:
Regards
Solution
Ok, case closed:
Failure was to not adress the scene to the linechart:
Scene secondScene = new Scene(secondaryLayout, 1200, 1600);
Fixed by obtaining the chart from the controller:
Scene secondScene = new Scene(chartWindowList.get(0).lineChartMain, 1200, 1600);
Answered By - pikkuez