Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 91767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:04:53+00:00 2026-05-10T23:04:53+00:00

I have a JPanel full of JTextFields… for (int i=0; i<maxPoints; i++) { JTextField

  • 0

I have a JPanel full of JTextFields…

for (int i=0; i<maxPoints; i++) {     JTextField textField = new JTextField();     points.add(textField); } 

How do I later get the JTextFields in that JPanel? Like if I want their values with

TextField.getText(); 

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:04:54+00:00Added an answer on May 10, 2026 at 11:04 pm

    Well bear in mind they didn’t get there by them selves ( I think a read some questions about dynamically creating these panels at runtime )

    In the answers posted there, someone said you should kept reference to those textfields in an array. That’s exactly what you need here:

    List<JTextField> list = new ArrayLists<JTextField>();  // your code... for (int i=0; i<maxPoints; i++) {      JTextField textField = new JTextField();     points.add(textField);     list.add( textField ); // keep a reference to those fields. } 

    // Later

    for( JTextField f : list ) {     System.out.println( f.getText() ) ; } 

    Wasn’t that easy?

    Just remember to keep these kinds of artifacts ( list ) as private as possible. They are for your control only, I don’t think they belong to the interface.

    Let’s say you want to get the array of texts, instead of

     public List<JTextField> getFields(); 

    You should consider:

     public List<String> getTexts(); // get them from the textfields ...  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPanel that looks something like this: JPanel panel = new JPanel();
I have JPanel in a container of a JFrame called Box public Box(){ add(new
I have a JPanel that I want to add some components. in particular JButton
I have a JPanel that uses FlowLayout. I add a number of JLabels to
I have a JPanel that has a button in it. The location of the
I have a JPanel that encapsulates two JPanels, one on top of the other.
I have a JPanel that implements custom drawing to draw a background. Over this,
I have a JPanel with one component that I want to place in an
I have a JPanel that I have created a MouseListener for and I am
I have Java application which adds JTextFields @ runtime to JPanel. Basically user clicks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.