views:

31

answers:

2

Hi,

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.

A: 

You could wrap the JEditorPane inside of a JScrollPane. You could then grab the scrollbars from the JScrollPane and adjust them percentage-wise. If you need to adjust them pixelwise then you can calculate the percentage you need to move by comparing the pixels you need to move with the total size of the JEditorPane. You should be able to adjust the UI of the JScrollPane so the scroll bars aren't visible.

Pace
Can you say, which property in JScrollPane to use to adjust this?
Joe
+2  A: 

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));
Mark Peters