Am a newbie to JFrame
, am designing an application... In that I have created 16 checkboxes, each assigned different value... Now my question is when a JCheckBox
is checked I want to write that value in a JFormattedTextField
...
I have added Checkboxes like this
JCheckBox[] jbx = new JCheckBox[16];
for(int i = 0; i < jbx.length; i++) {
if(i%2 == 0) {
jbx[i].setBounds(x_axis-300,y_axis,300,40);
panel.add(jbx[i]);
} else {
jbx[i].setBounds(x_axis,y_axis,300,40);
panel.add(jbx[i]);
y_axis += 30;
}
}
Can anyone please help me to do this...?
Edited....
I used this code
b.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
System.out.println(e.getStateChange() == ItemEvent.SELECTED ? "Selected" : "Deselected");
}
});
When i tried arithmetic operation instead of printing, its not worked...
setBounds(...)
this makes for very inflexible GUI's that while they might look good on one platform look terrible on most other platforms or screen resolutions and that are very difficult to update and maintain. Instead you will want to study and learn the layout managers and then nest JPanels, each using its own layout manager to create pleasing and complex GUI's that look good on all OS's. Your current code suggests that you want to use a GridLayout with 2 columns.