How can i add data from jcombobox to txt file in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How can i add data from jcombobox to txt file in java?

8th Feb 2020, 3:07 PM
arezoo
2 Answers
+ 2
here is the only answer I found but I don't know If this is what you are looking for https://stackoverflow.com/a/3173295/7218253
8th Feb 2020, 3:57 PM
BroFar
BroFar - avatar
+ 2
String s = ""; for(int i = 0; i < yourCombobox.getItemCount(); i++){ s += yourCombobox.getItemAt(i).toString() + "\n"; } Now write 's' to file. To retrieve, read s from file and split("\n") to get your items in an array. Note: Your items are saved as strings. Saving java object directly is possible but beyond the scope of this answer.
8th Feb 2020, 4:25 PM
Dan Rhamba
Dan Rhamba - avatar