Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java: Detecting backspace JTextArea

  • 11-02-2004 12:12pm
    #1
    Posts: 0


    Hey all,

    Could anyone tell me how to detect when a backspace key results in the cursor returning to the previous line (thus reducing the number of lines in the area) ?

    I have a subclass of PlainDocument which can detect the '\b' character but how could I find out if I have returned to a previous line?

    Any help on this would be great,
    thanks :)


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    I'm sure there's probably a prettier way of doing it, but set a variable noOfLines to 1 at the start. If you add a KeyListener to the Textarea, and on every key press, do a getLineCount(), then compare it to noOfLines, you can determine if you have gone up or down by one line. Then you change noOfLines to match getLineCount().

    I've never used a JTextArea before, so I'm not sure if it returns the number of actual lines (i.e. the number of String preceded or ended by '\n', regardless of how many rows in the TextArea) or the number of rows being used in the TextArea. Perhaps countRows() may do that.


  • Posts: 0 [Deleted User]


    I'll give that a try, thanks for the reply


Advertisement