Search code examples
javajeditorpane

Move the position in JEditorPane


I've a JEditorPane inside a JDialog. I'm loading a web page when this JDialog is loading. This web page is larger then the JEditorPane size. So I want to display a certain position in the web page by default.

For example, I've a 175x200 size jdialog and JEditorPane. I want to display the web page content around 150 pixels down.

Is there any solutions for this? Or is there any other component which I can used to display web pages and can move to a certain position of the web page at loading time.


Solution

  • Another option, if you don't want scroll bars (personally I think Pace has the best answer in that you should just show the scroll bars and scroll it to visible) would be to use the JViewport by itself:

        JViewport viewport = new JViewport();
        viewport.setView(editor);
        viewport.setViewPosition(new Point(0, 150));
        viewport.setViewSize(new Dimension(175, 200));
        viewport.setPreferredSize(new Dimension(175, 200));