MAKE A STRING OF JTEXTFIELD VARIABLE

Mark Devid

Total Post:102

Points:714
Posted by  Mark Devid
Java  Array  String 
 497  View(s)
Ratings:
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..
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: Make a string of JTextField variable

    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]);
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!