How can I get a single line from a jTextArea control?
Printable View
How can I get a single line from a jTextArea control?
Note that the "BadLocationException" is thrown if the line number specified didn't existCode:public String getLineText(int lineNumber)
{
try
{
int startIndex = jTextArea1.getLineStartOffset(lineNumber);
int endIndex = jTextArea1.getLineEndOffset(lineNumber);
java.lang.String line = jTextArea1.getText().substring(startIndex, endIndex - startIndex);
return line;
}
catch (BadLocationException ex)
{
return "";
}
}