18.24.2.222 writes:
Does anyone know a way to display a TextArea so that only one line at a time shows? That is, I am trying to make a TextArea look like a text field using a GridBagLayout and I am not succeeding. Any help would be greatly apprciated. Thanks.
Randy
152.205.22.243 writes:
TextArea's have a constructor which allow you to specify the number of rows.
TextArea( int iRows, int iColumns )
Is there a problem using that?
MikeD
18.24.2.222 writes:
I am using this to create my TextArea
TextAre textArea = new TextArea("", 1, 100, TextArea.SCROLLBARS_NONE);
and it still shows up with two rows. I even do a System.out.println(textArea.getRows()); and it
prints out 1 so I am stumped as to how to make it really only have one row instead of two (I can even type into two
different rows on the display). I could even deal with 2 rows if the user was only allowed to type in the first row. Any
suggestions would be greatly appreciated.
Thanks
Randy
152.202.134.36 writes:
You can control the length of the string that the user can type by adding a java.awt.event.TextListener to the TextArea. The TextListener would look as follows.
import java.awt.event.TextListener;
OneRowLimitingTextListener implements
TextListener
{
textValueChanged
(
TextEvent teChange
)
{
int iMawRowLength;
int iCurrRowLength;
TextArea txtaParent =
((TextArea) teChange.getSource());
String strText = txtaParent.getText();
iMaxRowLength = txtaParent.getColumns();
iCurrRowLength = strText.length();
//to keep the second line empty and allow
//the user to type on the first line
if (iCurrRow > iMaxRows)
{
txtaParent.replaceRange(strText.substring(0,
strText.length - 1)), 0, iMaxTextLength);
}
}
}
hope that helps
MikeD