I just started designing the GUI for an application that I'm writing..
And, well, I can't get either the awt.TextArea OR the swing.JTextArea to work properly.
Here are snapshots of both, along with the problems I am experiencing.

If anyone can resolve these problems, please let me know..
I wanted to use JTextArea but it produces errors and functions terribly.
Both examples are enclosed in a JScrollPane, the JTextArea makes use of the Scrollbars, the TextArea does not (though it works well otherwise, besides displaying its OWN scrollbars).

Pay no attention to the sloppiness, the JLabels, etc, as I've just begun putting the GUI together. ;)

Swing.JTextArea -- Produces errors during runtime, JScrollBar works, but widgit functions terribly

Awt.TextArea -- Works welll, but isn't displaying its own ScrollBars properly, nor does it make ues of the JScrollPane

And yes, I've called the...

JSP.setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JSP.setHorizontalScrollBarPolicy (JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

And the...

new TextArea("", 5, 5, TextArea.SCROLLBARS_BOTH);

Recommended Answers

All 5 Replies

Create scrollbars that with swing constants that suit you, then setWrapStyleWord(true) to the text area. Then add the JTextArea TO THE JSCROLLBAR. (Then the scrollbar to the container)

JTextArea textarea = new JTextArea(params);

JScrollPane test = new JScrollPane(textarea,


Yep. That's pretty much what I had:

JTextArea output = new JTextArea("");
//output.setEditable (false); // leave true while testing

JScrollPane JSP = new JScrollPane (output);
JSP.setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JSP.setHorizontalScrollBarPolicy (JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

add (JSP);

Did you add the scrollpane to the tabbedpane and then the tabbedpane to the container? Remember, there is no need to add the textarea to the container since it alread has a 'container' and the same with the scrollpanes if you want them on the tabbed pane

:cool: There was nothing wrong with my code.

It was the JRE/JDK..
I installed version 1.5 (I was using 1.4.2) and it works perfectly now.

Sorry for the confusion, but if anyone else encounters this problem, and if they read this, then they'll know what to do..

Note to all:
Suse 10.1 Linux; java-1.4.2; GUI problems

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.