• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

setText to dynamically created textField  RSS feed

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have jPanel1 with jTextField1 and addTfButton. By addTfButton I am adding dynamic tf to jPanel2.
Using this code I want to load text file data to jTextField1 and dynamically created tf:

The contents of file.txt:

On jTextfields I want to show just values: a, b, c.
But output looks like this:

I would like to ask how can I get this output:

Thank you in advance for any help.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem has nothing to do with I/O and Streams, I shall move this to the beginners forum.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is down to the way you are assigning values to text fields. The loop over the al List is not required but each time the while loop runs you should assign the s[2] value firstly to the known field and then to each subsequent element in the al List.

It would be easier to code if you added the known field, jTextField1, to the first index of the al List then you could simply have an index counter which increments each time the while loop is run selecting the text fields in turn to add the end of the next line of data to.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed to this code:

But output I am getting last s[2] value:
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You while loop reads a different line from the file with each iteration and so for each iteration you need to assign the s[2] value to a different text field. What is your code doing?
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot understand how to assign s[2] to different textfield.
My code is wrong because it is reading just s[2] of end row.
 
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tai Yo wrote:I have changed to this code: . . .

Before you change the code, make sure you format it correctly; that code is not correctly indented and there seems to be a } missing at the end, probably on the next line which you haven't shown us. Indentation is not there so Winston and I can read the code, but so you can read the code. If you had indented the code correctly, you would have seen what is going wrong sooner. You also seem to have a class called subPanel; that should start S not s.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for replies. The problem was fixed: I was overriding tf instances of each SubPanel.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!