0

I have parent panel and child panel. child parent exists on parent panel. Both are Jpanels of different size. Now i want to show a ChartPanel on the child panel. I have tried various ways of displaying it but unsucessfull. Please suggest some way of adding chartpanel to Jpanel.

sorry i couldnt paste the code. I have also tried various ways suggested in stackoverflow Q&A, but in vain.

chaitu
  • 1,036
  • 5
  • 20
  • 39
  • Not sure what exactly your problem is. I worked with jfreechart in the past. I have created it with JFreeChart chart = ChartFactory.createTimeSeriesChart(...); ChartPanel panel = new ChartPanel(chart); ChartPanel is of type JPanel. Probably you must set layout of your child panel? – ka3ak Aug 29 '12 at 10:32
  • 1
    Instead of pasting the code, please edit your question to include a _new_ [sscce](http://sscce.org/) that shows your approach. – trashgod Aug 29 '12 at 10:33
  • @ka3ak what kind of parameters are need to be set in layout manager – chaitu Aug 29 '12 at 10:36

2 Answers2

3

Because ChartPanel establishes a preferred size and BoxLayout relies on the preferred size, let a newPanel extend Box using the desired orientation and add() both child and chartPanel to newPanel.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • See also this [answer](http://stackoverflow.com/a/10277372/230513) and the source of [`ChartPanel`](http://www.jfree.org/jfreechart/api/javadoc/src-html/org/jfree/chart/ChartPanel.html#line.246). – trashgod Aug 29 '12 at 10:49
1

I think your problem has nothing to do with JFreeChart. Probably the code below helps you to start:

                JFrame frame = new JFrame();

                JPanel parentPanel = new JPanel();
                parentPanel.setBorder(BorderFactory.createTitledBorder("parent panel"));

                JPanel childPanel = new JPanel();
                childPanel.setBorder(BorderFactory.createTitledBorder("child panel"));
                // Add a button to the child panel
                childPanel.add(new JButton("button"));
                // In the instruction below you have to create and add your ChartPanel
                childPanel.add(yourChartPanel);
                parentPanel.add(childPanel);

                frame.add(parentPanel);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
ka3ak
  • 2,435
  • 2
  • 30
  • 57