The View Classes

Now that we have an overview of what views are and how they fit together, we’ll take a closer look at each of the public view classes, starting with the abstract base class, View.

The View Class

This abstract class represents how a single Element is displayed within a document. It defines properties and behavior common to different types of views. As we showed in Figure 23.2, all other view classes extend from View.

Properties

The View class defines the properties shown in Table 23.2. The attributes property defines the AttributeSet used by the view to render an Element. By default, the Element’s attributes are used. However, view objects should access the attributes through the getAttributes() accessor, to allow view-specific attributes to be added to the Element’s attributes or to allow the attributes to be converted in some way by the view subclasses.

Table 23-2. View Properties

Property

Data Type

get

is

set

bound

Default Value

alignment (indexed)

float

•

   

0.5

attributes

AttributeSet

•

   

from the Element

container

Container

•

   

from parent

document

Document

•

   

from the Element

element

Element

•

   

from constructor

endOffset

int

•

   

from the Element

maximumSpan (indexed)

float

•

   

if resizeWeight==0, preferredSpan, else Integer.MAX_VALUE

minimumSpan (indexed)

float

•

   

if resizeWeight==0, preferredSpan, else 0

parent

View

• ...

Get Java Swing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.