移动 JEditorPane 中的位置

发布于 2024-09-06 00:52:57 字数 227 浏览 3 评论 0原文

我在 JDialog 中有一个 JEditorPane。当加载此 JDialog 时,我正在加载网页。 该网页大于 JEditorPane 的大小。所以我想默认显示网页中的某个位置。

例如,我有一个 175x200 大小的 jdialog 和 JEditorPane。我想将网页内容向下显示 150 像素左右。

有什么解决办法吗?或者是否有任何其他组件可以用来显示网页,并且可以在加载时移动到网页的某个位置。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不爱素颜 2024-09-13 00:52:57

如果您不需要滚动条(我个人认为 Pace 有最好的答案,您应该只显示滚动条并将其滚动到可见),另一种选择是单独使用 JViewport:

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

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));
苏璃陌 2024-09-13 00:52:57

您可以将 JEditorPane 包装在 JScrollPane 内。然后,您可以从 JScrollPane 中获取滚动条并按百分比调整它们。如果您需要按像素调整它们,那么您可以通过将需要移动的像素与 JEditorPane 的总大小进行比较来计算需要移动的百分比。您应该能够调整 JScrollPane 的 UI,使滚动​​条不可见。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文