File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Need help with inputting data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need help with inputting data" Watch "Need help with inputting data" New topic

Need help with inputting data

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
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

Joined: Jul 26, 2007
Posts: 10815

Check out JSpinner

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.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
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.
I agree. Here's the link:
subject: Need help with inputting data
jQuery in Action, 3rd edition