very weird frame updating issue

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Gxb0514
Posts: 10
Joined: Mon Dec 02, 2013 2:30 am
antibot: No, of course not.

very weird frame updating issue

Post by Gxb0514 » Sun Dec 15, 2013 10:40 pm

Hi everyone. would like to share an issue I am having and see if anyone has any ideas. admittedly this may be more a java issue then a Jfreegraph one, but just in case let me explain.

I have created a rather complex graph that updates dynamically during runtime as per the code snippet below.
within Main

Code: Select all

    if(singleRun){
	  try{
		 FileInputStream fin = new FileInputStream("C:\\eclipse\\data\\so.gad");
		 ObjectInputStream ois = new ObjectInputStream(fin);
		 SO = (GAStatisticObject) ois.readObject();
	     ois.close();
	    }
	    catch(FileNotFoundException FNFE){System.out.println("file not found"); System.exit(1);}
	    catch(ClassNotFoundException CNFE){System.out.println("class not found");System.exit(1);}
	    catch(IOException IOE){System.out.println("error during data save: "); IOE.printStackTrace();System.exit(1);}
	  
	    GenotypeSimulator GS = new GenotypeSimulator(SO, populationSize); //statistic object, population size, enable immediately
	    GS.simulateEvolution();   	
    }
basically, read data from and object file
create a new simulation engine (GenotypeSimulator), which in turn creates and instantiates the GUI and charts.
and then start the simulation which basically reads the data file one data point at a time and updates the graphs. (code for simulator is below)

Code: Select all

    //only used for live execution monitoring 
    public void simulateEvolution(){
	   
       for(int x=0; x<genNumberSolutionFound; x++){
    	//System.out.println("updating data. GEN # = " + (x+1));   

       	   try {Thread.sleep(1000);} 
       	   catch (InterruptedException e) {e.printStackTrace();}
       	
       	//data series 1
       	XYDataItem point1 = null;
       	if(x<genNumberSolutionFound-1){//parent vector is always 1 less in length then the rest
       	   point1 = new XYDataItem(new Double(x+1), new Double(selectedFitnessAvg.get(x)));    //parent select avg fitness
       	}
       	XYDataItem point2 = new XYDataItem(new Double(x+1), new Double(populationFitnessAvg.get(x)));  //avg fitness
       	XYDataItem point3 = new XYDataItem(new Double(x+1), new Double(populationSmallestFitness.get(x))); //low fitness
       	XYDataItem point4 = new XYDataItem(new Double(x+1), new Double(populationLargestFitness.get(x))); //high fitness
       	
       	//data series 2
       	XYDataItem point5 = new XYDataItem(new Double(x+1), new Double(cumulativeAllelDistributionVector.get(x))); //diversity
		
        Vector<XYDataItem> DI = new Vector<XYDataItem>();
       	DI.add(point1); //parent avg fitness
       	DI.add(point2); //avg fitness
       	DI.add(point3); //low fitness
       	DI.add(point4); //high fitness
       	DI.add(point5); //average diversity
        	
       	LGP.updateAllDataSeries(DI, new Integer(sizeOfPopulation*(x+1)));
       	BGP.updateDataSet(x+1, instantaneousAllelDistributionMatrix.get(x));
       }
       
       BGP.setGARunComplete();
   }
(note I added a sleep timer just to make the update slow down a little)

THIS WORKS GREAT! as can be seen from the picture below. all my lineseries and bargraphs update perfectly.

Image

now here is where the problem comes in. What I really want to do is start the simulation from another JFrame when I click on a JButton; instead of from my main function directly. So I created a new "execution control panel" (top left in the figure below) and when you click on the start button, it executes exactly the same code previously displayed within its event handler (read object, create simulator, and then start the simulation).

however, as you can see from the figure, all I get is a window that is mostly blank and no longer updates dynamically like before. I know the simulation is running fine because I still see the println statements to StdOut, but the GUI remains blank until the "evolveSolution()" method completes and then updates all at once.

Image

anyone have any idea why I am getting this different behavior when executing from another GUI?

thanks. this one really has me stumped.

Gxb0514
Posts: 10
Joined: Mon Dec 02, 2013 2:30 am
antibot: No, of course not.

Re: very weird frame updating issue

Post by Gxb0514 » Sun Dec 15, 2013 10:45 pm

also, note that it's not just the charts that don't display, but also some of the other panels that hold various JLabels and JTextFields. basically, it just a blank frame.
this seems to suggest this is a java issue not a JFreeChart one. Hopefully someone ran into this before and has a way around it.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: very weird frame updating issue

Post by david.gilbert » Mon Dec 16, 2013 8:57 am

My guess is you have code updating the UI on a different thread to the EDT, try this utility to find out for sure:

https://weblogs.java.net/blog/alexfroms ... swing.html
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Gxb0514
Posts: 10
Joined: Mon Dec 02, 2013 2:30 am
antibot: No, of course not.

Re: very weird frame updating issue

Post by Gxb0514 » Wed Dec 18, 2013 1:03 am

Yep

that was it,

Java event handlers must execute in a somewhat restrictive way. the charts would not update until the event handler was finished. I wrapped the instantiation of the chart and the subsequent data updates into a threat and it worked beautifully.

thanks.

Giorgio

Locked