vaske
vaske

Reputation: 9552

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.

Upvotes: 0

Views: 780

Answers (1)

jitter
jitter

Reputation: 54605

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 e.g. JFrame and you are done.

Upvotes: 1

Related Questions