Solved

java.awt.TextArea

Posted on 1997-08-15
6
270 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
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

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


0
 

Author Comment

by:cadillac
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:cadillac
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now