Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Using a custom Document implementation with JTextArea

Reply
Thread Tools

Using a custom Document implementation with JTextArea

 
 
Brian J. Sayatovic
Guest
Posts: n/a
 
      09-07-2003
I just made my own, optimized Document implementation for use in a
JTextArea. I optimized it to handle large amounnts of text in anappend-only
fashion. However, when I put it to use, I get a NullPointerException deep
down inside PlainView:

java.lang.NullPointerException
at javax.swing.text.PlainView.getLineWidth(Unknown Source)
at javax.swing.text.PlainView.getPreferredSpan(Unknow n Source)
at javax.swing.plaf.basic.BasicTextUI$RootView.getPre ferredSpan(Unknown
Source)
at javax.swing.plaf.basic.BasicTextUI.getPreferredSiz e(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at javax.swing.JTextArea.getPreferredSize(Unknown Source)
at
javax.swing.text.JTextComponent.getPreferredScroll ableViewportSize(Unknown
Source)
at javax.swing.JTextArea.getPreferredScrollableViewpo rtSize(Unknown
Source)
at javax.swing.ViewportLayout.preferredLayoutSize(Unk nown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at javax.swing.ScrollPaneLayout.preferredLayoutSize(U nknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
...

The problem boils down to the fact that my Document implementation initially
has no content whatsoever. Thus, the root Element, which represents the
entire Document, has no child elements. This leaves the longestLine member
inside PlainView as null, so any call utilizing it, including
getLineWidth(), will throw a NullPointerException.

Now, I read that the default Documents utilize a scheme where their Content
always has an extra character at the end to allow for the caret to be placed
at the end of the real content. I imagine this means that even an empty
PlainDocument, for example, always has at least one element representing
that single newline character used in practice.

Is it necessary to do this in my case, or is there an easy way to subclass
PlainView and force my JTextArea to use this subclass instead?

Regards,
Brian.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insertion Sort : C++ implementation 100 times slower than C implementation sanket C++ 7 11-03-2011 05:00 AM
Knowing the implementation, are all undefined behaviours become implementation-defined behaviours? Michael Tsang C Programming 54 03-30-2010 07:46 AM
Knowing the implementation, are all undefined behaviours become implementation-defined behaviours? Michael Tsang C++ 32 03-01-2010 09:15 PM
GUI Newb... Im not sure how to make this work. (Auto-scrollbars using a JTextArea) Inertia_sublimation Java 10 01-01-2004 10:32 PM
Tab key on JTextArea Ahmed Moustafa Java 1 06-28-2003 03:25 PM



Advertisments