I have an User Interface where the user inputs a number (10 for example) in a textfeild then if the user presses enter I want 10 text feilds to be generated in the same User Interface.
how can I do that?
Roughly assuming some thing about layout manager you're using I'd say this:
public List<JTextField> addComponents( int number ) {
List<JTextField> fields = new ArrayList<JTextField>( number );
for( int i = 0; i < number; i++ ) {
fields.add( new JTextField() );
panelToAddComponentsTo.add( fields.get( i ) );
}
return fields;
}
if the user presses enter I want ? text feilds to be generated in the same User Interface
You add an ActionListener to the text field. The ActionListener will be invoked when the Enter key is pressed.
In the ActionListener code you need to parse the number entered and then loop to create and add the text fields to your panel:
for (...)
{
panel.add( new JTextField(...) );
}
panel.revalidate(); // needed when dynamically adding/removing components
panel.repaint(); // sometimes needed