you need to define a key listener and inside that surely we need to define implemented methods , the next code is my solution I hope it helps.
////
textfield.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if(textfield.getLineCount() == maximum_number_of_your_default) {
c = ta.getCaret();
// c is an object of Caret class as : Caret c; initialization only.
a = c.getDot();
// a is an integer value initialized by zero as : int a = 0;
}
if(ta.getLineCount() > maximum_number_of_your_default){
c.moveDot(a);// To retrieve the caret to the last row.
}
// to show line segment on the output with each enter-press key :
if(e.getExtendedKeyCode() == KeyEvent.VK_ENTER)
System.out.println("!!!!!" + ta.getLineCount() + " "
+ ta.getText());
}
// default methods of KeyListener class
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
});
////
It my idea I hope it is correct , good luck, one world , one god , one solution for each .