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.

Results 1 to 7 of 7

Thread: How do I center JTextField (an array!)

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How do I center JTextField (an array!)

    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 .

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How do I center JTextField (an array!)

    how to do this if it an array like this :
    How many items are in the array?
    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.

  3. #3
    Junior Member
    Join Date
    Mar 2018
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How do I center JTextField (an array!)

    Quote Originally Posted by Norm View Post
    How many items are in the array?
    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]
    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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How do I center JTextField (an array!)

    I know how to do this for normal JTextField
    Replace the "normal" with the array notation: theArrayName[theIndex]

    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.

  5. The Following User Says Thank You to Norm For This Useful Post:

    ahmed2009 (March 7th, 2018)

  6. #5
    Junior Member
    Join Date
    Mar 2018
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How do I center JTextField (an array!)

    Everything is solved now thanks a lot.

  7. #6
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I center JTextField (an array!)

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

  8. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How do I center JTextField (an array!)

    @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.

Similar Threads

  1. How to center ListView text
    By RaiOh in forum Android Development
    Replies: 0
    Last Post: February 16th, 2014, 02:42 PM
  2. Array Output in JTextField
    By shodai in forum AWT / Java Swing
    Replies: 3
    Last Post: April 14th, 2013, 07:20 PM
  3. Action Center problem
    By lf2killer in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 23rd, 2012, 05:31 AM
  4. Want to move my button away from center.
    By Fendaril in forum AWT / Java Swing
    Replies: 2
    Last Post: November 6th, 2009, 10:05 PM
  5. The Frame to be Center Position
    By r12ki in forum AWT / Java Swing
    Replies: 3
    Last Post: October 1st, 2009, 10:36 AM

Tags for this Thread