我有一个 Groovy 应用程序,它使用通过 swing 构建器构建的滚动 Pane :
BinsicWindow(def controller)
{
controlObject = controller
swinger = new SwingBuilder()
mainFrame = swinger.frame(
title: "Binsic is not Sinclair Instruction Code",
size:[640, 480],
show:true,
defaultCloseOperation: WindowConstants.DISPOSE_ON_CLOSE){
scrollPane(autoscrolls:true) {
screenZX = textArea(rows:24, columns:32) {visble:true}
}
screenZX.setFont(new Font("Monospaced", Font.PLAIN, 18))
}
}
我以编程方式将文本添加到文本区域(即没有用户输入),并且我希望文本区域在添加内容时自动向下滚动。但 View 仍然固定在顶部,我只能通过拖动鼠标看到底部(一旦屏幕超过全屏)。
我可以解决这个问题吗?我已经寻找这个问题的答案有一段时间了,但一无所获。如果这是一个简单的答案,我们深表歉意。
最佳答案
以下几行应将文本区域滚动到最后一个文本位置:
rect = screenZX.modelToView(screenZX.getDocument().getLength() - 1);
screenZX.scrollRectToVisible(rect);
关于java - 让我的scrollPane在程序控制下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10921024/