我处理JEditorPane
显示HTML文档和我创建了一个按钮,我点击它,“因为如果我翻书页”每次哪些滚动我下一个视口。力的JScrollBar滚动到行头
但是,有时我会在视口顶部看到一行的一部分,所以有什么办法可以强制JScrollBar
滚动到一行的前面?
我试过setBlockIncrement()
成员方法,但它并没有在所有的工作。
在这里,你是我最好的尝试:
//get the visible rectangle as well as the most bottom right point.
Rectangle rec = jEditorPane1.getVisibleRect();
Point pt = new Point((int)rec.getX() +(int)rec.getWidth(),(int)rec.getY() + (int)rec.getHeight());
// get the offset of the most bottom right point
int off = jEditorPane1.viewToModel(pt);
try {
//get next viewable rectangle and scroll to it
rec = jEditorPane1.modelToView(off+100);
rec.height = jEditorPane1.getVisibleRect().height;
jEditorPane1.scrollRectToVisible(rec);
} catch (BadLocationException ex) {
Logger.getLogger(NewJFrame2.class.getName()).log(Level.SEVERE, null, ex);
}
为了尽快提供更好的帮助,请发布[SSCCE](http://sscce.org/)(您的最佳尝试)。 –
顺便说一句 - 如果一条线嵌入了图像,并且图像高度大于视图端口的可视高度,会发生什么? –
感谢您的回复,视口是全屏幕,我正在编辑自定义的epub文件。然而;如果您所描述的图像存在,那么唯一的办法就是使用一条线或一个图像来启动视口,但是它很长。 – muaz