GeeCON Prague 2014*
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
Author

Need help with inputting data

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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: 10426
    
    8

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.


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

Joined: Apr 11, 2005
Posts: 744
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.
 
GeeCON Prague 2014
 
subject: Need help with inputting data