gpt4 book ai didi

java - 将scrollPane添加到EditorPane(网页)

转载 作者:行者123 更新时间:2023-12-01 14:18:02 25 4
gpt4 key购买 nike

当我们按下按钮时,我向 JFrame 添加了一个网页(网页在同一框架中打开)。效果很好。但我想向其中添加一个scrollPane,但是当我添加 JScrollPane jsp = new JScrollPane(jep);(jep = JEditorPane) 时,网页不会显示。

如果需要,我会在此页面添加更多信息。

代码(主要部分)

            JEditorPane jep = new JEditorPane();
jep.setEditable(false);
try {
jep.setPage("xxxxxxxxxxxxx");
} catch (IOException error) {
jep.setContentType("text/html");
}
jep.setBounds(100, 50, 150, 100);
JScrollPane jsp = new JScrollPane(jep);
add(jsp)
add(jep);

谢谢~3751_Creator

最佳答案

原因是这一行:

jep.setBounds(100, 50, 150, 100);

您已经设置了 JEditorPane 的边界,但现在您已将该 JEditorPane 添加到 JScrollPane 中。因此,您应该为 JScrollPane 使用 setbounds,而不是为 JEditorPane 设置边界。

<小时/> 这一切都是关于不显示 JEditorPane 的原因。但是现在这里给您一个严肃的建议: 强烈建议不要使用 setBounds。您应该使用内置布局来对齐 Swing 中的组件。 Java AWT 和 Swing 为此类任务提供了许多有用的布局。看A Visual Guide to Layout Managers了解如何使用这些布局。

关于java - 将scrollPane添加到EditorPane(网页),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17931916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com