我在渲染网页,并试图滚动到内它的位置。 然而,滚动不起作用。
这是我的代码...
import org.lobobrowser.html.*;
import org.lobobrowser.html.gui.HtmlPanel;
import org.lobobrowser.html.parser.*;
import org.lobobrowser.html.test.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class finall {
Node goTo;
public void show(URL url,Node theFinalNode) throws MalformedURLException, IOException, SAXException {
goTo = theFinalNode;
String uri=url.toString();
URLConnection connection = url.openConnection();
InputStream in = connection.getInputStream();
Reader reader = new InputStreamReader(in);
InputSource is = new InputSourceImpl(reader, uri);
UserAgentContext uAgent=new SimpleUserAgentContext();
final HtmlPanel htmlPanel = new HtmlPanel();
HtmlRendererContext rendererContext = (HtmlRendererContext) new LocalHtmlRendererContext(htmlPanel, uAgent);
DocumentBuilderImpl builder = new DocumentBuilderImpl(uAgent, rendererContext);
Document document = builder.parse(is);
JFrame frame = new JFrame();
frame.getContentPane().add(htmlPanel);
htmlPanel.setDocument(document, rendererContext);
frame.setSize(300, 450);
frame.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
htmlPanel.scrollTo(goTo);
}
});
}
可能有人请帮助我理解为什么滚动不起作用。