JavaFX 8 Tutorial 61 - Retrive Database Values Into CheckBox
The code written in this tutorial is -
// Retrive Hobbies Into CheckBox
if(rs.getString("Hobbies")!= null){
checkBox1.setSelected(false);
checkBox2.setSelected(false);
checkBox3.setSelected(false);
//hobbies in the string formate - [Playing , Dancing]
System.out.println(rs.getString("Hobbies"));
String checkBoxString = rs.getString("Hobbies").replace("[", "").replace("]", "");
System.out.println(checkBoxString);
//now can converert to a list, strip out commas and spaces
List<String> hobbylist = Arrays.asList(checkBoxString.split("\\s*,\\s*"));
System.out.println(hobbylist);
for(String hobby : hobbylist){
switch(hobby){
case "Playing" : checkBox1.setSelected(true);
break;
case "Singing" : checkBox2.setSelected(true);
break;
case "Dancing" : checkBox3.setSelected(true);
break;
default : checkBox1.setSelected(false);
checkBox2.setSelected(false);
checkBox3.setSelected(false);
}
}
}else{
checkBox1.setSelected(false);
checkBox2.setSelected(false);
checkBox3.setSelected(false);
}
Comments
Post a Comment