Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将JscrollPane添加到JTextPane_Java_Swing - Fatal编程技术网

Java 将JscrollPane添加到JTextPane

Java 将JscrollPane添加到JTextPane,java,swing,Java,Swing,我正在尝试将JscrollPane添加到我的JTextPane中,但在运行它时它不会显示。我在网上搜索过,大多数答案都毫无帮助 这就是我在代码中实现它的方式 JTextPane t = new JTextPane(); JScrollPane s = new JScrollPane(t); s.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

我正在尝试将JscrollPane添加到我的JTextPane中,但在运行它时它不会显示。我在网上搜索过,大多数答案都毫无帮助

这就是我在代码中实现它的方式

    JTextPane t = new JTextPane();
    JScrollPane s = new JScrollPane(t);
    s.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    t.setBounds(10,50,60,70);
    s.setBounds(10,50,60,70);
    Pane.add(t);
    Pane.add(s);

首先去除
t.setBounds(10,50,60,70)
s.setBounds(10,50,60,70)
窗格。添加(t)。通过调用
窗格,组件只能驻留在单个容器中。添加(t)
您正在将组件从其父容器中移除(“代码>JScrollPane

此外,请确保使用适当的布局管理器来管理布局(无需调用
setBounds


您可能还希望通读,这将使人们更容易阅读您的代码,您也更容易阅读其他人的代码