Hi java people! I've really been having a hard time getting my head around this. First of all, I have this class which builds a GUI, which is pretty much exactly the layout I want.
Okay, now run it. You see that large JPanel on the left. I want to get a chart of some description to take up that space. I've been using JFreeChart, and I'm more or less used to making them at this point, but they always open in their own screen when I try and combine them with the above class. Since I haven't really decided what type of chart needs to go in there yet, here is a sample one from the JFreeChart people themselves, which i was using to get some grasp of how to manipulate charts inside a panel:
So, given this example, how would I get the charts from the second class at the location I want in the first class?
Okay, this is probably a stupid thing to ask, but I'm fairly new. When you say "child" does that mean the same thing as it does when talking about inheritance?
Terry Flint wrote:Okay, this is probably a stupid thing to ask, but I'm fairly new. When you say "child" does that mean the same thing as it does when talking about inheritance?
No !!! You have a JPanel so just use it's add() method to add the ChartPanel to it. Frequently one can just use the ChartPanel instad of the JPanel so where in your code you add the JPanel your may be able to just add the ChartPanel.
Okay, I actually thought this would be easy to figure out, since it sounds like it should be simple. I have no idea how to get this line to be read by the statistics class.
My usual instinct would be to create a getter for chartPanel , but since it is already inside the createFrame1 method, that won't work. I also tried making the createFrame1 method public and returning chartPanel instead of the frame itself, but that just causes a compile error. I'm sure I'm missing something obvious, but I just can't see it.
Don't try to cobble together the two disjoint bits of code. Extract the few lines of code that create the ChartPanel from the JFreeChart example and insert them into the method that creates the graphing panel. You can then discard the rest of the JFreeChart example code. You will need to write your own code to populate the JFreeChart model but for test purposes you can just copy the example createDataset() method into your class. Later you can modify the createDataset() method so it populates the chart with your own data.
I actually just managed to get what I wanted, but I did cobble the code together a bit. I will try and do it the way you just recommended though. For the sake of those that may be having problems with this in the future, I'll post the solution when I manage to do it the correct way. For now, I'm considering this problem to be resolved.