1

I have built an display a TabPanel. At this stage no Chart is displayed .When I click on a button, I build a new chart an add it to the panel. But nothing happens. I have to click on the panel to have the chart displayed at last.

So I put a repaint() on the TabPanel which contains the ChartPanel but with no effect. Am I missing something here ?

        if(myChart==null){
            myChart = new PortfolioChart(portfolioModel.getDataMatrix());
            add(myChart.createPanel(), BorderLayout.CENTER);
            repaint();
        }else{
            myChart.setPortfolio(portfolioModel.getDataMatrix());
            myChart.updateDataSet();

        }   

May be I should put the repaint() instruction on something differrent ?

user3239711
  • 639
  • 1
  • 7
  • 24

1 Answers1

1

In the complete example shown here, each tab has a ChartPanel. Rather than replacing the chart, each chart's data model is updated periodically, and the listening chart repaints itself in response.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • My construction is nearly the same as yours... but, I only add a chart when the button is pushed. In your algorithm, all the charts are built before the Pack() instruction. The problem is probably there. – user3239711 Feb 04 '14 at 13:58
  • My "Add" button adds a new chart after `pack()` when the button is pushed; you should't have to `revalidate()`. – trashgod Feb 04 '14 at 15:29