File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with inputting data

 
colin shuker
Ranch Hand
Posts: 750
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic