i have a window with one text field in it that accepts an int, and as soon as a user enters that int i want a window to appear with the entered amount of text fields. and as soon as the user enters the data in those text fields, my program needs to store the data in those text fields in an array or vector or something so i can access it later
i know ill have to use a for loop with the entered number and create the textfields and add them to a panel, but how do i refer to them when i dont know how many there will be?
chop ficaro wrote:i know ill have to use a for loop with the entered number and create the textfields and add them to a panel, but how do i refer to them when i dont know how many there will be?
You can add them in a List when you create them, and loop through that list.
Christophe is right. You essentially turn a List<JTextField> into a List<String> by calling getText for each of the text fields. Perhaps you can switch to using JTextField[] and String[] instead as the size never changes once created.