简体   繁体   中英

How to add scrollable JTextArea to jDesktopPane

I was try several opinion but neither of them it seams to work.

This method returns 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.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.

You need to use JInternalFrame too. JDesktopPane is supposed to be parent container for JInternalFrame objects.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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