aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to connect a JPanel created by JFreeChart to JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to connect a JPanel created by JFreeChart to JFrame" Watch "How to connect a JPanel created by JFreeChart to JFrame" New topic
Author

How to connect a JPanel created by JFreeChart to JFrame

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Dear boss,
This question may be trivial

http://www.java2s.com/Code/Java/Chart/JFreeChartPieChartDemo1.htmSorry about the naming, Panel == Canvas here. No time to correct.
Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
You should have corrected that naming conflict because you would not be able to compile the code otherwise, and you are doubtless using copy‑and‑paste to post your code.
You should be adding that panel in your initComponents method, and it must be before your setVisible(true) call if you want to see it. Or you have to call validate() or revalidate().

Moving discussion to our GUIs forum.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Your createDemoPanel() method returns JPanel, so you add it to your frame like you would with any other:


Note that methods in your class shouldn't be static and there is no need for that class to extends ApplicationFrame.


The quieter you are, the more you are able to hear.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Kemal Sokolovic wrote:Your createDemoPanel() method returns JPanel, so you add it to your frame like you would with any other:


Note that methods in your class shouldn't be static and there is no need for that class to extends ApplicationFrame.


Thanks Sokolovic, it works, want to give you 2 plus'es.
Update: it only works once :S
When I change the code, it works, but it stops working afterwards...
It looks very wierd, it comes on and off.






Jack
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
I think invalidate() might not quite be the correct method to call.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

What do you mean by:
... but it stops working afterwards...


You should add your panel to frame before you invoke setVisible(true). As Mr Campbell pointed out, invalidate() shouldn't be there.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Thanks, everybody, it works like a charm!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
You’re welcome

And it’s Mr Ritchie not Mr Campbell
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Campbell Ritchie wrote:And it’s Mr Ritchie not Mr Campbell


If you found yourself offended, that certainly wasn't my intention.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
If I’d been offended, I would not have used the

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to connect a JPanel created by JFreeChart to JFrame