๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How can I limit a JTextPane length ?

#9270
From: John P. McGrath
Date: Wed, 19 Apr 2000 00:00
41 lines
2559 bytes
On Tue, 18 Apr 2000 17:37:50 +0200, Jean-Fran๏ฟฝois Leroux wrote:

> If I understand correctly, I have to add a document
> listener o the text pane and limit this one instead
> of the pane itself.  Is it what the doc call the
> 'ModelView' (didn't catch exactly what was meant
> by that...) ?

Yes, you got it.

In a Model-View architecture, the code that stores the data (the Model) 
is kept separate from the code that displays the data (the View).  Swing 
classes use this approach.  You may also hear Model-View-Controller, but 
in Swing, the view and the controller are combined.  In your example, the 
JTextPane is the view and the Document is the model.  (The Document 
interface is used as the model for all Swing text components).

In general, these different parts interact as follows:  The controller 
interacts with the view and recognizes events.  It decides how to react 
to the event, and tells the model what changes should be made.  When the 
model changes its state, it notifies any listeners that have registered 
themselves with the model, and the view is normally one of those 
listeners.  When the view is notified of a change, it updates itself.

For the most part, Swing view components provide methods to manage and 
access the model, so you can just use the view component and forget that 
the model is there.  The view will create an instance of the appropriate 
model when you create the view, and it provides various methods that just 
forward to the model, such as the getText() and setText() methods.

There are many advantages to this approach.  For example, to create a 
text editor with a split view, you could create two JTextPanes that share 
the same underlying model.  Each view (JTextPane) can be looking at a 
different part of the model, or they could be looking at the same part.  
In that case, when you type into one pane, the changes would be reflected 
in the other.

-- 
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID: <MPG.1366fba05e182d4e98988d@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8dftfj$ps89@bornews.borland.com> <MPG.1365a23a1575dd52989885@forums.borland.com> <8dhut3$g6a7@bornews.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 111d45,aa99ae09612c00a7
X-Google-Attributes: gid111d45,public
From: John P. McGrath <JPMcGrath@fast.net>
Subject: Re: How can I limit a JTextPane length ?
Date: 2000/04/19
Message-ID: <MPG.1366fba05e182d4e98988d@forums.borland.com>
X-Deja-AN: 612985055
References: <8dftfj$ps89@bornews.borland.com> <MPG.1365a23a1575dd52989885@forums.borland.com> <8dhut3$g6a7@bornews.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing