Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: Cannot find symbol CENTER when using setAlignment with FlowLayout

  1. #1
    bobcowher is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Cannot find symbol CENTER when using setAlignment with FlowLayout

    Good afternoon. I'm fairly new to Java and this is my first post here so please feel free to chime in if I'm posting this to the wrong place or my question isn't suitable to this forum.

    I'm attempting to use FlowLayout to structure a very simple graphical window that changes its' structure when buttons are clicked. When using the FlowLayout object I've created, I'm getting errors like the one below. I'm using the latest versions of NetBeans and the JDK.

    cannot find symbol
    symbol: variable LEFT
    location: class FlowLayout


    I'll paste my code and the full barrage errors below. Your thoughts on this are appreciated.

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package flowlayout;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    /**
     *
     * @author CowherRM
     */
    public class Layout extends JFrame{
        
        private JButton lb;
        private JButton cb;
        private JButton rb;
        private FlowLayout layout;
        private Container container;
        
        public Layout(){
            super("The Title");
            layout = new FlowLayout();
            container = getContentPane(); 
            setLayout((LayoutManager) layout);
            
            lb = new JButton("Left");
            add(lb);
            
            //Left Stuff in here
            lb.addActionListener(
                    new ActionListener(){
                        @Override
                    public void actionPerformed(ActionEvent event){
                            layout.setAlignment(FlowLayout.LEFT);
                            layout.layoutContainer(container);
                            
                        }
                    }
            );
            
            cb = new JButton("Center");
            add(cb);
             //Center Stuff in here
            cb.addActionListener(
                    new ActionListener(){
                        @Override
                        public void actionPerformed(ActionEvent event){
                            layout.setAlignment(FlowLayout.CENTER);
                            layout.layoutContainer(container);
                            
                        }
                    }
            );
            
            rb = new JButton("Right");
            add(rb);
             //Center Stuff in here
            rb.addActionListener(
                    new ActionListener(){
                        @Override
                        public void actionPerformed(ActionEvent event){
                            layout.setAlignment(FlowLayout.RIGHT);
                            layout.layoutContainer(container);
                            
                        }
                    }
            );
                    
        }
       
    }
    
    ant -f C:\\Users\\CowherRM\\Documents\\NetBeansProjects\\FlowLayout jar
    init:
    deps-jar:
    Created dir: C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\build
    Updating property file: C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\build\built-jar.properties
    Created dir: C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\build\classes
    Created dir: C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\build\empty
    Created dir: C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\build\generated-sources\ap-source-output
    Compiling 2 source files to C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\build\classes
    C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\src\flowlayout\Layout.java:36: error: cannot find symbol
                            layout.setAlignment(FlowLayout.LEFT);
      symbol:   variable LEFT
      location: class FlowLayout
    C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\src\flowlayout\Layout.java:37: error: cannot find symbol
                            layout.layoutContainer(container);
      symbol:   method layoutContainer(Container)
      location: variable layout of type FlowLayout
    C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\src\flowlayout\Layout.java:50: error: cannot find symbol
                            layout.setAlignment(FlowLayout.CENTER);
      symbol:   variable CENTER
      location: class FlowLayout
    C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\src\flowlayout\Layout.java:51: error: cannot find symbol
                            layout.layoutContainer(container);
      symbol:   method layoutContainer(Container)
      location: variable layout of type FlowLayout
    C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\src\flowlayout\Layout.java:64: error: cannot find symbol
                            layout.setAlignment(FlowLayout.RIGHT);
      symbol:   variable RIGHT
      location: class FlowLayout
    C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\src\flowlayout\Layout.java:65: error: cannot find symbol
                            layout.layoutContainer(container);
      symbol:   method layoutContainer(Container)
      location: variable layout of type FlowLayout
    6 errors
    C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\nbproject\build-impl.xml:926: The following error occurred while executing this line:
    C:\Users\CowherRM\Documents\NetBeansProjects\FlowLayout\nbproject\build-impl.xml:268: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 1 second)

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Cannot find symbol CENTER when using setAlignment with FlowLayout

    Are you sure you're using the FlowLayout that contains those variables and methods? In other words, do you have another class named FlowLayout somewhere?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    bobcowher is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Re: Cannot find symbol CENTER when using setAlignment with FlowLayout

    I'm not overriding the FlowLayout class from java.awt(I believe that's where it's coming from) if that's what you're asking. It's a very small program. The rest of my code is below and basically just calls the class that I posted before.


    Java Code:
    package flowlayout;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    /**
     *
     * @author CowherRM
     */
    public class FlowLayout {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            Layout l = new Layout();
            l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            l.setSize(300,100);
            l.setVisible(true);
            
            
            
        }
    }

  4. #4
    bobcowher is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Re: Cannot find symbol CENTER when using setAlignment with FlowLayout

    I'm an idiot. Forget I asked....

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Cannot find symbol CENTER when using setAlignment with FlowLayout

    Quote Originally Posted by bobcowher View Post
    I'm an idiot. Forget I asked....
    You aren't an idiot; this is a pretty common mistake. Lesson learned: don't create classes with the same name as existing Java classes.
    gimbal2 likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. cannot find symbol
    By vastrolorde in forum New To Java
    Replies: 11
    Last Post: 01-04-2013, 12:11 PM
  2. Cannot find symbol
    By dest in forum New To Java
    Replies: 3
    Last Post: 04-03-2012, 06:38 PM
  3. can't find symbol
    By globo in forum New To Java
    Replies: 21
    Last Post: 01-17-2011, 05:06 AM
  4. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 09:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •