#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0

    Swing Checkboxes


    I am trying to work with and learn the swing items, like checkboxes. This is the code I have:

    Code:
    public class Testing extends JApplet {
    
        Container cp = getContentPane();
        JTextArea instruct = new JTextArea(10,30);
        JCheckBox c1 = new JCheckBox("Option 1");
        JCheckBox c2 = new JCheckBox("Option 2");
        JCheckBox c3 = new JCheckBox("Option 3");
        JCheckBox c4 = new JCheckBox("Option 4");
        
                
        public void init() {
    
            setOptions();
        }
    
        
    
        
        public void setOptions() {
            cp.setLayout(new FlowLayout());
            cp.add(instruct);
            instruct.append("Select options:");
            cp.add(c1);
            cp.add(c2);
            cp.add(c3);
            cp.add(c4);
        }
    }
    The result is that only c4 (the checkbox labeled "Option 4") is displayed. What am I missing here?

    Thanks.
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Try changing the layout to a FlowLayout.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by bullet
    Try changing the layout to a FlowLayout.
    Is it something other than this

    Code:
    cp.setLayout(new FlowLayout());
    that I have to do?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by adampjr
    Is it something other than this

    Code:
    cp.setLayout(new FlowLayout());
    that I have to do?
    Nevermind, my browser was still loading on older version of the applet for some reason. This actually works.

IMN logo majestic logo threadwatch logo seochat tools logo