aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes variable number of text fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "variable number of text fields" Watch "variable number of text fields" New topic
Author

variable number of text fields

chop ficaro
Ranch Hand

Joined: May 02, 2010
Posts: 30
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variable number of text fields