我正在处理JEditorPane
显示 HTML 文档,我创建了一个按钮,每次单击它时都会滚动到下一个视图端口,“就好像我在翻一页书一样”。
但是,有时我会在视口顶部看到一行的一部分,那么有没有办法强制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);
}