September 1st, 2013, 08:12 PM
-
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.
September 1st, 2013, 08:33 PM
-
Try changing the layout to a FlowLayout.
September 1st, 2013, 09:18 PM
-
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?
September 2nd, 2013, 02:45 PM
-
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.