Search code examples
javaswingjpaneljinternalframejchart2d

Inserting a chart to a internal jframe


I have a program were I want to have a plotter that updates in realtime. I am going to use jchart2d, but how do I integrate that into my swing gui? I have a internalframe but it does not seem to take my chart. That is the jInternalFrame has no contents.

private void initObjects(){
    trace =new Trace2DLtd(200);
    trace.setColor(Color.Blue);
    Chart2D.cjart = new Chart2D();
    chart.addTrace(trace);
    jInternalFrame1.getContentPane().add(chart);
   }

later on when I update

 public void update()
{ trace.addPoint(elapsedtime,activity)}

What am i doing wrong


Solution

  • InternalPie is a complete example that adds a ChartPanel to a JInternalFrame.

    Addendum: Like JFrame, JInternalFrame defaults to BorderLayout and add() forwards to the content pane's BorderLayout.CENTER; pack() should precede setVisible().

    ChartPanel cp = new ChartPanel(chart);
    JInternalFrame jif = new JInternalFrame("Chart", ...);
    jif.add(cp);
    jif.pack();
    jif.setVisible(true);
    

    image