I'm using the xchart library for Java and I'm creating a chart as follows:
XYChart chartHR = QuickChart.getChart("Title", "Time", "y", "randomWalk", new double[] { 0 }, new double[] { 0 });
chartHR.getStyler().setLegendVisible(false);
chartHR.getStyler().setXAxisTicksVisible(false);
SwingWrapper<XYChart> swHR = new SwingWrapper<XYChart>(chartHR);
swHR.displayChart().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
I'm creating this chart in a thread launched from my main class. Everytime I close the chart my whole application is closed. How can I prevent that?
Here is the minimal working example:
package test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
TestThread testThread = new TestThread();
testThread.start();
String input = "";
Scanner scanner = new Scanner(System.in);
while (!input.equals("q")) {
System.out.print("Enter 'q' for termination.");
input = scanner.nextLine();
}
scanner.close();
}
}
package test;
import javax.swing.JFrame;
import org.knowm.xchart.QuickChart;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
public class TestThread extends Thread {
private SwingWrapper<XYChart> swHR;
private XYChart chartHR;
public void run() {
chartHR = QuickChart.getChart("Test", "Time", "y", "randomWalk", new double[] { 0 }, new double[] { 0 });
chartHR.getStyler().setLegendVisible(false);
chartHR.getStyler().setXAxisTicksVisible(false);
swHR = new SwingWrapper<XYChart>(chartHR);
swHR.displayChart().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
while(true) {}
}
}