[英]JtextArea scrolling text up by one page
I have a JtextArea (in a scrollPane) in which i have 20 lines of text. 我有一个JtextArea (在scrollPane中),其中有20行文本。
The display capacity of the textArea is 10 lines. textArea的显示容量为10行。
I need to move the 20 lines of text up by one page leaving a blank screen to type if user press enter.So if user scrolls up he will be able to see the 20 lines. 我需要将20行文本向上移动一页,如果用户按Enter键会留下空白屏幕进行键入,因此如果用户向上滚动则可以看到20行文本。
The functionality is similar to clear command in linux which will move all the contents up by one page. 该功能类似于linux中的clear命令,它将所有内容上移一页。
How can i achieve this in JtextArea ?? 我如何在JtextArea中实现此目标 ?
Please help. 请帮忙。
Try by adding \\n * 20 times every time the user presses enter. 尝试在用户每次按Enter时加\\ n * 20次。 You can do this by implementing a KeyListener, but some would not agree on using KeyListener, I do not see why not.
您可以通过实现KeyListener来做到这一点,但是有些人不同意使用KeyListener,我不知道为什么不这样做。
jTextArea.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt) {
if (evt.getKeyCode() == KeyEvent.VK_ENTER)
for (int i = 0; i < 20; i++)
jTextArea.append("\n");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.