The following approach demonstrates how you can stroll displayed web page (document) at specified position using JavaScript: (以下方法演示了如何使用JavaScript滚动到网页文档的指定位置:)
import com.teamdev.jxbrowser.chromium.Browser; import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent; import com.teamdev.jxbrowser.chromium.events.LoadAdapter; import com.teamdev.jxbrowser.chromium.swing.BrowserView; import javax.swing.*; import java.awt.*; /** * This sample demonstrates how to scroll document programmatically. */ public class ScrollDocumentSample { public static void main(String[] args) { Browser browser = new Browser(); BrowserView view = new BrowserView(browser); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(view, BorderLayout.CENTER); frame.setSize(600, 500); frame.setLocationRelativeTo(null); frame.setVisible(true); browser.addLoadListener(new LoadAdapter() { @Override public void onFinishLoadingFrame(FinishLoadingEvent event) { if (event.isMainFrame()) { event.getBrowser().executeJavaScript( "window.scrollTo(document.body.scrollWidth, " + "document.body.scrollHeight);"); } } }); browser.loadURL("http://www.teamdev.com"); } }