简体   繁体   English

如何将可滚动的JTextArea添加到jDesktopPane

[英]How to add scrollable JTextArea to jDesktopPane

I was try several opinion but neither of them it seams to work. 我尝试了几种意见,但没有一条可以奏效。

This method returns JTextArea 此方法返回JTextArea

    private static JTextArea getJArea() {
    if (jArea == null) {
        jArea = new JTextArea();
        jArea.setBounds(new Rectangle(16, 153, 468, 139));
        jArea.setVisible(true);
        jArea.setLineWrap(true);
        jArea.setWrapStyleWord(true);
        jArea.setEditable(false);
        jsp.getViewport().add(jArea);

    }
    return jArea;
}

and i JDesktopPane i add this area with this code snippet 和我JDesktopPane我使用此代码段添加此区域

jDesktopPane.add(getJArea(), null);

And this not work, I was try to create a JScrollPane and assign JTextArea to him and add that to the JDesktopPane, but that also doesn't work. 而且这不起作用,我试图创建一个JScrollPane并将JTextArea分配给他,然后将其添加到JDesktopPane中,但这也行不通。

You need to use JInternalFrame too. 您还需要使用JInternalFrame JDesktopPane is supposed to be parent container for JInternalFrame objects. JDesktopPane应该是JInternalFrame对象的父容器。

JInternalFrame iframe = new JInternalFrame("Title", true, true, true, true);
iframe.setSize(180, 150);
iframe.setVisible(true);
iframe.getContentPane().add(new JScrollPane(new JTextArea("TestText",20,20)));
JDesktopPane desktop = new JDesktopPane();
desktop.add(iframe);

Then add the JDesktopPane to eg JFrame and you are done. 然后将JDesktopPane添加到例如JFrame ,就可以完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM