Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i need to position my Caret

 
Ola Kesh
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have a project am currently working on and i have a code such as this:
JTextArea a = new JTextArea();
. . .
. . .
. . .
a.getText();
a.setText(null); // to reset the JTextArea

at the output, i realised the Caret is not set, i have to click the JTextArea b4 it is set.
please what should i do?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't knwo whether this will sort out your problem, but try resetting your text to empty string rather than null. See whether that makes any difference.

CR
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and are there any methods in JTextArea or its superclasses like requestFocus() ? That might help, too. Have a look in the API, see what it says.

CR
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic