Java swing button doesn't add new container component -


I have the following swing app. The problem is that I want the click button action to add new components to Container C. Whenever the method is called separately inside the consolidator, the chart is added when the method AddGraph () is called. However, if I call it within the action () the chart is not added. I have tried to return the AddGraph () chart object and add it to actionPerformed () , but it still does not work, it should be something very basic I can not find the right way to do this.

  Public class mainframe extends JFrame {chartpanel chart panel; Public manframe (string title) {super (title); // Set Layout Manager Setline (new border layout ()); // Create Swing Components JButton Button = New Pocket ("Click Me"); // Add swing components to the content pane. Last container c = getContentPane (); C. (Button, border layout. South); AddGraph (c); // button behavior here button. AddActionListener (New Executioner) {@ Override Public Zero Action Perfid (ActionAge RGET) {// AddGraph (c);}}); } Public Zero AddGraph (Container C) {. . . Chart panel = new chartpanel (chart); ChartPanel.setPreferredSize (new java.awt.Dimension (500, 270)); C.add (Chart Panel, Border Layout, CA); }}  

container or constructor Add Public Graphics AddGraph () {Add Charts Panel} to {public} and c

  . Chart panel = new chartpanel (chart); ChartPanel.setPreferredSize (new java.awt.Dimension (500, 270)); // container c = getContentPane (); C.add (Chart Panel, Border Layout, CA); }  

Comments