Make a string of JTextField variable

Total Post:102

Java  Array  String 
 879  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..
  1. Post:397

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