How to auto scroll JTextArea
on middle mouse button click? To be clear, when we click the mouse wheel (middle button) in Firefox (for example) and push it down/up we will be able to scroll the page automatically when we release the middle button, we can alo see a round icon at the point of middle button click.
Here is a screenshot of it.
I think there is no such functionality for JTextArea
in Java. Is there any hack to implement it.
Any answer is appreciated.
To determine which of the Mouse buttons is pressed, these three methods from SwingUtilities
could help you:
Based on the mouse button clicked, you can take appropriate action to scroll the JTextArea programmatically. Probably, you can use something like this:
textArea.setCaretPosition(textArea.getDocument().getLength());
-> to move to the end of the JTextArea
You can look at this link to get a good idea of positioning the cursor position in JTextArea
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.