Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: printing an array in a text field
|
Posted: Dec 13, 2002 3:16 PM
|
|
A JTextField (or TextField) is a single-line edit box, so you have to first decide how you want to separate the strings in the array. After you have made that decision, it is a simple matter to do as you intimated and gather all the lines together in a StringBuffer, then use one call to setText(). You could do it without the StringBuffer (this is what you were asking, I think) by doing a loop something like this:
if( strings.length > 0 )
{
editBox.setText( strings[0] );
String sep = " "; // Space, or whatever you like.
for( int i = 1; i < strings.length; i++ )
editBox.setText( editBox.getText() + sep + strings[i] );
}
else
editBox.setText( "" );
Of course, this second method is grossly inefficient, especially if there are several billion strings in the array. Hmm... that isn't too likely now is it? So either method is equally acceptible.
|
|