当我们按下按钮(网页在同一帧中打开)时,我在我的JFrame中添加了一个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
发布于 2013-07-29 19:33:16
原因是这条线:
jep.setBounds(100, 50, 150, 100);您已经为JEditorPane设置了界限,但现在已经将JEditorPane添加到JScrollPane中。因此,与其为JEditorPane设置界限,还不如为JScrollPane使用setbounds。
这一切都是没有出现JEditorPane的原因。但是现在给您一个严肃的建议:,setBounds的使用是非常不鼓励的。您应该使用内置的布局来对齐Swing中的组件。Java和Swing为此类任务提供了许多有用的布局。查看 布局管理器视觉指南 ,了解如何使用这些布局.
https://stackoverflow.com/questions/17931916
复制相似问题