Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use "setCaretPosition"

 
ho mingchang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;
public class TextAreaExample {
public static void main(String argv[]) {
Frame f = new Frame("TextArea Example");
f.setLayout(new FlowLayout());
String str = "1234567890 234567890 34567890 4567890 567890";
TextArea ta3 = new TextArea(str, 2, 10, TextArea.SCROLLBARS_VERTICAL_ONLY);
f.add(ta3);
ta3.setCaretPosition(0);
f.pack();
f.setVisible(true);
}
}
When I compiled the file, it showed "Cannot set caret position until after the peer has been created". How should I modify the code?
Thank you very much for your help ^^
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, ho mingchang!
I'm moving this to the Swing / JFC / AWT forum...
[ July 13, 2003: Message edited by: Dirk Schreckmann ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic