I am developing a simple “To-do List” application which involves obtaining ‘things to do’ for
a particular day from the database and displaying them as checkbox text on a panel resting on a frame.There is a button “done” which can be used to remove
the ticked checkboxes after a task is complete.
The code that I used for the dynamic creation of the checkboxes is shown below:
//cnt-variable used to store the number of tasks for a day
//rs1-ResultSet variable into which the task description is read into.
//DATA-variable with 'to-do' description
for(int i=0;i<cnt&&rs1.next();i++)
{
String s2=rs1.getString("DATA");
JCheckBox cb = new JCheckBox("New CheckBox");
cb.setText(s2);
cb.setVisible(true);
jPanel1.add(cb);
jPanel1.validate();
}
On running the code all it displays is an empty frame with the panel. Could someone help me figure out why the check boxes are not being displayed?
Thanks in advance.
Try this. This allows you to create a random number of check boxes…