Multiple JFreeChartPanels in a JInternalFrame or JFrame ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Mudit Wahal

Multiple JFreeChartPanels in a JInternalFrame or JFrame ?

Post by Mudit Wahal » Tue Jul 16, 2002 6:33 pm

Hi all,

Has anyone tried adding multiple JFreeChartPanels in a single JInternalFrame or JFrame ?

I'm using an MDI (multiple document interface ??) application which draws one chart per JInternalFrame . Now I want to add multiple charts in the JInternalFrame but whatever I do, boxlayout, flow etc etc, I only see the first chart panel which I added. I dont see any other charts at all. I even changed the size as per my frame size for all other charts. Still, only the first chart. If I pack the frame, then thats the only chart in the frame and no blank spaces. If I dont pack, then I see blank spaces in the frame.

I want to create a frame where I've 2 charts on the left, one above another taking up 1/3rd of the frame length and a big chart on the right taking up the remaining space in the frame.

Thanks

Mudit

Harald Faber

Re: Multiple JFreeChartPanels in a JInternalFrame or JFrame

Post by Harald Faber » Wed Jul 17, 2002 8:14 am

Did you also try adding the FreeChartPanels each into a normal JPanel and add them to the frame, probably GridBagLayout?
-> 3 JFreeChartPanels => 3 JPanels with maybe a "super" panel which contains the 3 JPanels would be my idea to implement. Working with panels make many tasks easy to solve...

Mudit Wahal

Re: Multiple JFreeChartPanels in a JInternalFrame or JFrame

Post by Mudit Wahal » Wed Jul 17, 2002 10:40 pm

Okay, this is what I did:

JPanel chartPanel = mycharts.getChartPanel(); // returns the JFreeChartPanel object for this chart

JInternalFrame f = new JInternalFrame(); // create a JInternalFrame (similar to JFrame)

// now create a new JPanel, use gridbaglayout to store the chartPanel in 3 different cells

GridBagLayout gbLayout = new GridBagLayout();
JPanel newJP = new JPanel();
newJP.setLayout(gbLayout);

newJP.add(chartPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

newJP.add(chartPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

newJP.add(chartPanel, new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0
,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

// get the container of the JInternalFrame
Container content = f.getContentPane();

// add to the JInternalFrame
content.add(newJP);

------------------------------

I still see only 1 chart and lots of blank spaces and not three. Also, if I pack the Frame, then no blank spaces.

Thanks
Mudit

Harald Faber

Re: Multiple JFreeChartPanels in a JInternalFrame or JFrame

Post by Harald Faber » Thu Jul 18, 2002 8:40 am

The first point I see is that you try to add the same chartPanel 3x into your newJP. Is that what you want? Is it possible that this might cause the trouble you have?
Second you set two of your 3 GridBagConstraints to NONE. Maybe you could try BOTH although this is only for expanding the component if smaller than the cell.
Another idea is: Some components, like JTextField, need to be CENTERed or so to be able to expand itself. Of course this is for BorderLayout.

Mudit Wahal

Re: Multiple JFreeChartPanels in a JInternalFrame or JFrame

Post by Mudit Wahal » Thu Jul 18, 2002 4:36 pm

Harald,

I changed NONE to BOTH for the remaining two. I also created three JPanels and added the chart panel individually to the three jpanels. I created a frame and then I added all three JPanels into the frame. Then I added this frame to my JInternalFrame. Here is the modified code. Regarding same chartpanel being added, its an experiment right now. Can this be a problem ?
--------------------------------------------
GridBagLayout gbLayout = new GridBagLayout();
JPanel[] newJP = new JPanel[3];
JFrame newjf = new JFrame();
newjf.getContentPane().setLayout(gbLayout);

for (int i = 0; i < 3; i++)
{
newJP = new JPanel();
}



newJP[0].add(chartPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
newJP[1].add(chartPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
newJP[2].add(chartPanel, new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0
,GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

for (int i = 0; i < 3; i++)
newjf.getContentPane().add(newJP);

// content points to the JInternalFrame.getContentPane()
content.add(newjf.getContentPane());
------------------------------------------------------------

Thanks

Mudit

Harald Faber

Re: Multiple JFreeChartPanels in a JInternalFrame or JFrame

Post by Harald Faber » Thu Jul 18, 2002 4:57 pm

Try out yourself, it would be the first I'd check: If it works in a normal JFrame without adding this JFrame into another JInternalFrame. If it still does not work I'd suppose some problem with the layout as I already stated concerning flexible components and being centered.

Mudit Wahal

Re: Multiple JFreeChartPanels in a JInternalFrame or JFrame

Post by Mudit Wahal » Thu Jul 18, 2002 7:39 pm

Okay, I created different chartPanels in a single JInternalFrame and it works. Somehow, and for a reason I dont know, you CAN NOT add the same panel twice .. why ? maybe some JAVA guru can answer this question.

Thanks

Mudit

Locked