1

I have a combinedXYPlot and a drop-down list. I want to update my chart based on user input from drop-down. How to do this? I tried the following code

frmJPanel.getContentPane().removeAll();

frmJPanel.setLayout(new BorderLayout());

initChart(option);

frmJPanel.repaint();

The changes are reflected only after I minimize/ maximize the window. What is the function that needs to be called? What is the better way to do this ?

sam
  • 651
  • 3
  • 9
  • 16

2 Answers2

1

I have my chart inside a org.jfree.chart.ChartPanel. When I want to update the chart I simply call on the chartPanel.repaint() method.

The chartPanel itself is added another JPanel, which in turn is placed in the main layout of the application.

Joachim H. Skeie
  • 1,893
  • 17
  • 27
1

ChartPanel "registers with the chart to receive notification of changes to any component of the chart. The chart is redrawn automatically whenever this notification is received." There are examples here and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I had to include the function call - frmPanel.validate() for the changes to be updated. – sam Aug 25 '11 at 02:20
  • I'm surprised. Is `frmPanel` a `JPanel` or a `ChartPanel`? Cf. this [example](http://stackoverflow.com/questions/7071057/how-do-i-rotate-tick-mark-labels-on-the-domain-of-a-number-axis-in-jfreechart/7073428#7073428), which inadvertently confounds the two. – trashgod Aug 25 '11 at 02:24
  • 1
    its a JPanel. It should have been frmJPanel.validate() – sam Aug 25 '11 at 04:01