🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1470

Re: jTextArea component - help an old newbee!!!

#1470
From: Paul Furbacher
Date: Sun, 30 Nov 2003 18:14
63 lines
3434 bytes
Algis Kabaila wrote:

> 1. I want to read lines from the jTextArea1 component as
> strings.  I am trying to use getText(int offs,int
> len)function.  Oops - I think I can see where I goofed:
> (in offs) probably referst to offset in bytes, not the
> line number...
> 
> 2. I want to process the data and write it back on the
> same jTextArea1 component.  As the first step of testing
> that procedure, I want to echo check the data by dumping
> it back onto the comoponent.

Any model for a JTextArea should implement Document.
The default model for JTextArea is
javax.swing.text.PlainDocument.

Since it looks as though you are going to use
a very simple document structure, you might
want to take advantage of the default document's
"getParagraphElement(int pos)" method.  The
default model is line-based, so "pos" is the
line number.

Using this method of getting each line obviates
the need to calculate offsets, etc., and may
make you code more readable.


On a side issue:

> Of course, it is nice to start with some of the work
> already done for you - I see no better way than to use an
> existing sample editor!  I have gone through the tutorial
> to become familiar with it and to produce a "new" code,
> being conscious of the copyrignt notice on the example.

Yes, and no.  The editor may in fact be far too
complicated, with features which get in the way,
rather than help.  I often use the samples as springboards
for testing ideas, but just as often, I'll start with
a blank slate.  The latter approach lets me concentrate
on just the issues related to a specific component.
Reducing the number of side effects which a complex
example may introduce can potentially save time.
But there's no "this way is the best way" in this
matter.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://www.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Technical Details
Message-ID: <3fca3399$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <bq3lia$1tiqfa$1@ID-216608.news.uni-berlin.de> <bq3n98$1ublqa$1@ID-216608.news.uni-berlin.de> <3fc78900$1@newsgroups.borland.com> <bqbe3a$1pq2v0$1@ID-216608.news.uni-berlin.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,663e7dcc14de267d
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2003-11-30 10:39:08 PST
Date: Sun, 30 Nov 2003 13:14:52 -0500
From: Paul Furbacher <pfurbacher@mac.com>
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5) Gecko/20031013 Thunderbird/0.3
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: jTextArea component - help an old newbee!!!
References: <bq3lia$1tiqfa$1@ID-216608.news.uni-berlin.de> <bq3n98$1ublqa$1@ID-216608.news.uni-berlin.de> <3fc78900$1@newsgroups.borland.com> <bqbe3a$1pq2v0$1@ID-216608.news.uni-berlin.de>
In-Reply-To: <bqbe3a$1pq2v0$1@ID-216608.news.uni-berlin.de>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 68.39.103.120
Message-ID: <3fca3399$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1070216089 68.39.103.120 (30 Nov 2003 10:14:49 -0700)
Lines: 64
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail