• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable number of text fields

 
chop ficaro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic