0

I used a code in order to display a graph. I want to insert a button in this graph (Show details) that i will used in order to present some details about the graph .I tried with this code but an error appear:"cannot add to layout:constraint must be a string" thanks.

if(jCheckBox1.isSelected()){
    try{

      Statement statement = con.createStatement(rs.TYPE_FORWARD_ONLY,rs.CONCUR_READ_ONLY);
      String sql1 = "Select last_updated_by,(count(id_incident) )*100/(Select count(id_incident) from incident where Status like 'Closed' and open_time between '"+date1+"' and '"+date2+"')from incident  where  Status like 'Closed'and open_time between '"+date1+"' and '"+date2+"' group by last_updated_by";
      rs1 = statement.executeQuery(sql1);
      DefaultPieDataset pieDataset = new DefaultPieDataset(); 
      while(rs1.next()){      
      pieDataset.setValue( rs1.getString("last_updated_by"),rs1.getDouble(2));                        
 }
      JFreeChart chart = ChartFactory.createPieChart3D("Taux résolution par personne",  pieDataset, true, true, true); 
 PiePlot3D piePlot3d = (PiePlot3D) chart.getPlot();
     piePlot3d.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}"));
  fenetre fen= new fenetre();
      JPanel pnl = new JPanel(new CardLayout()); 
   fen.setContentPane(pnl); 
fen.setVisible(true);
fen.setSize(500, 500); 
 showdetails = new JButton(new AbstractAction("showdetails") {

          @Override
          public void actionPerformed(ActionEvent e) {
              //To change body of generated methods, choose Tools | Templates.
          }
      }) ;

       ChartPanel cPanel1 = new ChartPanel(chart);    
        pnl.add(cPanel1,showdetails);
    File fichier = new File("C:\\Users\\Desktop\\résultat_application\\Taux résolution par personne de '"+date1+"' à '"+date2+"'.png"); 
       try { 
  ChartUtilities.saveChartAsPNG(fichier, chart, 400, 250); 
} catch (IOException e) { 
  e.printStackTrace(); 
}   
              }
           catch (Exception e) {
       JOptionPane.showMessageDialog(this,e);
              }
    }
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
jalel
  • 57
  • 3

1 Answers1

0

Error is in the line:

pnl.add(cPanel1,showdetails);

cPanel1 is a ChartPanel, showdetails is a Button - both are Components. However Container (from which JPanel inherits it's add methods) has no method that allows adding two components at once. What it does have, and the reason why it compiles is a method with the following signature:

add(Component comp, Object constraints)

And so it tries to match your button as a constraints object and decides that something is not right.

Deltharis
  • 2,320
  • 1
  • 18
  • 29