Skip to content
Advertisement

Cannot load a thread that loads chart from JFreeChart until clicked

I think I did everything right. All I want is to load the thread that contains chart after the main thread that loads the components and window is finished. But it didn’t work. Somehow I have to click jPanel1 (the panel that will load the chart) and the chart is loaded. Any help would be appreciated. What I’ve tried:

  • Changing the thread to SwingWorker
  • Changing the thread to invokeLater
JavaScript

Advertisement

Answer

Swing is single threaded and not thread safe. This means that you shouldn’t perform any long running or blocking operations with the context of the Event Dispatching Thread and you shouldn’t modify the state of the UI or any state the UI relies on, from outside the context of the EDT.

So, having said that, you’re createFrame1 might look something more like…

JavaScript

Alternatively, if loading the data takes time, you could publish each data point…

JavaScript

Runnable example…

enter image description here

JavaScript

And waiting for stuff to be done…

enter image description here

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement