2013-07-29 42 views
0

当我们按下按钮(网页在相同的框架中打开)时,我向我的JFrame添加了一个WebPage。它工作正常。但我想添加一个scrollPane,但是当我添加JScrollPane jsp = new JScrollPane(jep);(jep = JEditorPane)时,网页不会显示。将scrollPane添加到EditorPane(网页)

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

代码(主要部分)

  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

+0

您是否将JScrollPane添加到您的JFrame中? –

+0

如需更快获得更好的帮助,请发布SSCCE。 – tbodt

回答

1

原因是这样的线路:

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

你所设定的范围为JEditorPane但现在您已添加JEditorPaneJScrollPane。因此,您应该使用setbounds代替JScrollPane,而不是设置JEditorPane的界限。


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