HTMLドキュメントを表示することを扱ってJEditorPane
おり、「本のページをめくっているように」クリックするたびに次のビューポートにスクロールするボタンを作成しました。
ただし、ビューポートの上部に行の一部が表示されることがあるので、強制的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);
}