javaswingcompiler-errorsawtcannot-find-symbol

using getContentpane with FlowLayout to apply changes on Layout, but it does not work why?


Hi there I'm was trying to make 3 buttons(left, center, right) with actionListener, so when someone clicks on one of these buttons the alignment of FlowLayout of the frame change, but when I'm was trying to use getContentpane() method it's was not working correctly! here is my Code:

import javax.swing.JFrame;
import javax.swing.JButton;

import java.awt.*;
import java.awt.event.*;

public class FLowLayoutExample extends JFrame implements ActionListener{

public static FlowLayout flowLayout;
public static JButton left,center,right;

public FLowLayoutExample(){

flowLayout = new FlowLayout();

left = new JButton("left");
center = new JButton("center");
right = new JButton("right");


setSize(800,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(flowLayout);
add(left);
add(center);
add(right);

//Register a componentes with the listener
left.addActionListener(this);
center.addActionListener(this);
right.addActionListener(this);

setVisible(true);






    }
public static void main(String args[]){


new FLowLayoutExample();


}//End of main method

public void actionPerformed(ActionEvent e){

    if(e.getSource() == left){
        flowLayout.setAlignment(FlowLayout.LEFT);


        }
      flowLayout.layoutContainer(getContentpane());
    }
}//End of class

and I get this Error:

FLowLayoutExample.java:56: error: cannot find symbol flowLayout.layoutContainer(getContentpane()); ^ symbol: method getContentpane() location: class FLowLayoutExample 1 error


Solution

  • It should be typed as "getContentPane" and not "getContentpane".