I'm trying to dynamically add check boxes to a scroll pane depending on what is in my db. Currently i have
ResultSet rs = getAvailableUsers();
try {
while (rs.next()){
User temp = new User();
temp.setUsername(rs.getString("username"));
temp.setUserNo(rs.getInt("userno"));
JCheckBox tempCheckBox = new JCheckBox();
tempCheckBox.setText(temp.getUsername());
tempCheckBox.setVisible(true);
checkBoxes.add(tempCheckBox);
}
} catch (SQLException ex) {
Logger.getLogger(SelectProjectTeamGUI.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(checkBoxes);
panel.setLayout(new GridLayout(0,1));
panel.setVisible(true);
scrollPane.removeAll();
scrollPane = new JScrollPane(panel);
for (int i = 0; i < checkBoxes.size(); i++){
panel.add(checkBoxes.get(i));
//panel.repaint();
System.out.println(i);
}
scrollPane.setVisible(true);
I can see the outline for the scroll pane but none of the checkboxes are there. All the checkboxes are stored in a vector then pulled back out and added to the panel one at a time. Any ideas why it isn't showing anything? I know the checkboxes are in the vector as i've printed it out and seen them all there.
Thanks for your help in advance.