Solved

java.awt.TextArea

Posted on 1997-08-15
6
276 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

696 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