0

Hi!

Basically I am trying to add the graph inside the Jpanel which already exists. I am getting the erorr "adding a window to a container"

Here is my code

 public void displayGraph(){

    try{
       String sql = "Select pressure, ventilage from statstbl";
DBCon conn = new DBCon();
       JDBCCategoryDataset dataset = new JDBCCategoryDataset(conn.connect(),sql);
       JFreeChart chart = ChartFactory.createLineChart("Chart", "Pressure", "Ventilage", dataset, PlotOrientation.VERTICAL, false, true, true);
       BarRenderer renderer = null;
       CategoryPlot plot = null;
       renderer = new BarRenderer();
       ChartFrame frame = new ChartFrame("Statistics",chart);
 jPanel3.add(frame, BorderLayout.CENTER);
 jPanel3.validate();
       frame.setVisible(true);
       frame.setSize(500,650);

   }catch(Exception ex){
       JOptionPane.showMessageDialog(null,ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
   }



    }
2
Contributors
1
Reply
10
Views
2 Years
Discussion Span
Last Post by JamesCherrill
1

I guess your ChartFrame is a kind of JFrame - ie a top-level container or window, so you cannot place that inside a lower-level container like JPanel.

If you are usimg JFreeChart then you can replace your ChartFrame with a ChartPanel. ChartPanel is a kind of JPanel, and can be added to another JPanel without any problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.