Hello everyone ,
I know how to do this for normal JTextField but how to do this if it an array like this :
private JTextField[] userInput1;
I want everything typed in the center .
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello everyone ,
I know how to do this for normal JTextField but how to do this if it an array like this :
private JTextField[] userInput1;
I want everything typed in the center .
How many items are in the array?how to do this if it an array like this :
For example if there are 20 JTextField objects referenced in the array, where do you want all 20 of them displayed in the GUI?
To access one element of the array, use array notation: theArrayName[theIndex]
If you don't understand my answer, don't ignore it, ask a question.
I just want when the user type in the text field it should be in the center like this :
https://i.imgur.com/3iWBlAj.png
Replace the "normal" with the array notation: theArrayName[theIndex]I know how to do this for normal JTextField
If that is not your problem, please post the code you are having problems with and add some comments saying what the problem is. Be sure to wrap any posted code in code tags.
If you don't understand my answer, don't ignore it, ask a question.
ahmed2009 (March 7th, 2018)
Everything is solved now thanks a lot.
While you have created the 2D array to house your fields, you need to instantiate the JTextField components in your array.
for (int i =0; i < userInputArray.length; i++) {
for (int j =0; j < userInputArray[0].length; j++) {
userInputArray[i][j] = new JTextField();
}
}
@jackar56 What question are you trying to answer? I don't see a 2D array in OPs question.
If you don't understand my answer, don't ignore it, ask a question.