Home > DeveloperSection > Forums > Make a string of JTextField variable
Mark Devid
Mark Devid

Total Post:102

Points:714
Posted on    December-27-2015 11:20 PM

 Java Java  Array  String 
Ratings:


 1 Reply(s)
 226  View(s)
Rate this:
I make some variable by

        String[] StoreValueFromTable = new String[5];
        String[] ColumName = new String[5];
        for(int Count=0;Count<5;Count++){
            StoreValueFromTable[Count] = "MindStick"+Count;
            ColumName[Count] = "MS"+Count;
            System.out.println(StoreValueFromTable[Count]+", "+ColumName[Count]);
        }
I am trying to make JTextField[] Fiels[Count] = new JTextField(); it's giving me error. I am not sure, is there a way to make it dynamically..


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Supported
Posted on    December-27-2015 11:39 PM

Hi Mark,
This works for me :

final int TEXTFIELDS_COUNT = 5; 
// Create an array of 5 JTextFields
JTextField[] fields = new JTextField[TEXTFIELDS_COUNT];
for(int count = 0; count< TEXTFIELDS_COUNT; count++){
    // fields[count] represents a single JTextField
    fields[count] = new JTextField();
    // Do something with fields[count], like setting its text 
    // fields[count].setText("some text");
    StoreValueFromTable[count] = "QueryTechnica"+count;
    ColumName[count] = "QT"+count;
    System.out.println(StoreValueFromTable[count]+", "+ColumName[count]);
}

Don't want to miss updates? Please click the below button!

Follow MindStick