• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with inputting data

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a JFrame in where I need something like a JTextfield to enter a value, say 14.

Once 14 has been entered, I need to be able to enter 14 strings.

I could possible create a JPanel inside a scroll pane that has 14 JTextfields,
or possibly use a table, but that table would have to have 14 rows, which can only be known
if the first value entered triggers something to create this.

I'm wondering what other people would do here, I'd like an effective solution, I don't know if there is any
component that can help. I currently just enter the values on 1 line separated by commas, but say you didn't
enter the right amount, its not very user friendly that way.

Thanks for any help.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out JSpinner
Also http://java.sun.com/docs/books/tutorial/uiswing/components/spinner.html

You can configure your spinner with a SpinnerNumberModel
When the user changes any value, you can retrieve the selected number and dynamically populate your panel with the required number of fields.
I personally would prefer using text fields over table as text fields are more intuitive for the user.

PS. Don't forget to invoke revalidate and repaint (in that order) after you are done adding the fields to panel to get them to display properly.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I'll look into the SpinnerNumberModel.

The only thing is, it would be kind of nice to see the values you've entered at the same time, like you would with a bunch of text fields, but there could be an arbitrary number of textfields which makes it awquard.
reply
    Bookmark Topic Watch Topic
  • New Topic