Solved

java.awt.TextArea

Posted on 1997-08-15
6
275 Views
Last Modified: 2008-02-26
I am using a java.awt.TextArea and it will not seem to give me the Horizontal Scroll Bar when I appendText() to the TextArea that goes beyond the width of the TextArea.  Does anyone know why or how this could happen?  If so, how can I correct this?  Also, has anyone done anything before which will make the TextArea wrappable so that if text is appended to the textarea that is wider than its specified width, it will just automatically wrap to the next line?  If so, I would appreciate some help.  Thanks.
0
Comment
Question by:cadillac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:russgold
ID: 1225100
What VM are you using?  What version of Java?  appendText() works just fine for me in JDK 1.02.


0
 

Author Comment

by:cadillac
ID: 1225101
I am using it in Netscape Navigator Gold.

I believe you misunderstood the question...appendText() works fine.  I just used appendText as an example of when I add text to the text area.  If I add enough text where the string is longer than the textarea's width, it should open up the horizontal scrollbar, but it never does with mine.  I am not sure why.  Do you know how to make it so the textarea is just wrappable?
0
 
LVL 4

Accepted Solution

by:
russgold earned 50 total points
ID: 1225102
The behaviour you are seeing is incorrect, and due to a bug in Netscape 3.0's JVM. This is fixed in version 4 (Communicator)

JDK 1.1 adds a new constructor to TextArea which allows you to specify whether and which scrollbars are to be enabled. If you disable horizontal scrollbars, text will be word-wrapped automatically.

This behavior is unfortunately unavailable in JDK 1.02 (which Navigator Gold 3.0 uses).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cadillac
ID: 1225103
You don't know how to make the textArea wrappable using JDK 1.02 do you?  I am looking for a workaround for now...
0
 
LVL 4

Expert Comment

by:russgold
ID: 1225104
A workaround?  Well, there is a way, but it's kind of painful:

1. Subclass TextArea as a WordWrappingTextArea:

2. Add a private method which will take a raw string and word-wrap it by inserting returns ('\n') at the appropriate points.

3. Add another private method to remove the returns from such a string.

4. When *any* change is made to the text, remove any previous returns and insert new ones at the appropriate point (this means overriding handleEvent and catching each keystroke, as well as overriding appendText, insertText, replaceText, and setText).

5. Also, override getSelectedStart, getSelectedEnd, and select() to  accomodate the extraneous returns.

6. When a client asks for the current text (getText and getSelectedText), remove the extraneous keystrokes.

Once you have this class, you will have full control over word-wrapping, but your changes will be incompatible with JDK 1.1.
0
 

Author Comment

by:cadillac
ID: 1225105
Thanks

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question