









































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The layout policies in swing, including top-down and bottom-up layout approaches. It also discusses the boxes and glue layout model, springs and struts model, and constraints. The boxes and glue layout model is based on the tex document processing system and is used for tiled composition without overlap. The springs and struts model specifies a fixed offset or area to take up slack. Constraints are a more general approach for establishing and maintaining relationships between things, with the system automatically maintaining relationships under change.
Typology: Study notes
1 / 81
This page cannot be seen from the preview
Don't miss anything!










































































(^) interactor has changed appearance, moved, appeared, disappeared, etc. (^) done by “declaring damage” (^) each object responsible for telling system when part of its appearance needs update
(^) Can optimize somewhat (^) Multiple rectangles of damage (^) Knowing about opaque objects (^) But typically not worth the effort
JComponent RepaintManager repaint() addDirtyRegion() paintImmediately() paintComponent() paintBorder() paintChildren() Event Dispatch Queue
(^) Deciding size and placement of every object (^) easiest version: static layout (^) objects don’t move or change size (^) easy but very limiting (^) hard to do dynamic content (^) only good enough for simplest cases
(^) Change layout on the fly to reflect the current situation (^) Need to do layout before redraw (^) Can’t be done e.g., in paintComponent() (^) Why?
(^) invalidate() method (^) Called on a container to indicate that its children need to be laid out (^) Called on a component to indicate that something about it has changed that may change the overall layout (change in size, for example) (^) validate() method (^) Starts the process that makes an invalid layout valid--recomputes sizes and positions to get correct layout
(^) invalidate() is often called automatically (^) e.g., in response to changes to components’ state (^) ... but not always (^) e.g., if a JButton’s font or label changes, no automatic call to invalidate() (^) Mark the button as changed by calling invalidate() on it (^) Tell the container to redo layout by calling validate() on it (^) In older versions of Swing you had to do this by hand (^) Newer versions (post 1.2) add a shortcut: revalidate() (^) Invalidates the component you call it on (^) Begins the process of validating the layout, starting from the appropriate parent container (^) Validation also uses the RepaintManager
(^) Containers (parent components) can control size/position of children (^) example: rows & columns (^) Two basic strategies (^) Top-down (AKA outside-in) (^) Bottom-up (AKA inside-out)
(^) Parent determines layout of children (^) Typically used for position , but sometimes size (^) Example?
(^) Children determine layout of parent (^) Typically just size (^) Example?
(^) Children determine layout of parent (^) Typically just size (^) Shrink-wrap container (^) parent just big enough to hold all children (^) e.g., pack() method on JWindow and JFrame (^) Resizes container to just big enough to accommodate contents’ preferredSizes
(^) Need both (^) May even need both in same object (^) horizontal vs. vertical (^) size vs. position (these interact!) (^) Need more general strategies
(^) Swing layout policies are (generally) customizable (^) Some containers come with a “built-in” layout policy (^) JSplitPane, JScrollPane, JTabbedPane (^) Others support “pluggable” policies through LayoutManagers (^) LayoutManagers installed in Containers via setLayout() (^) Two interfaces (from AWT): LayoutManager and LayoutManager (^) Determines position and size of each component within a container (^) Looks at components inside container: (^) Uses getMinimumSize(), getPreferredSize(), getMaximumSize() (^) ... but is free to ignore these (^) Example LayoutManagers: (^) FlowLayout, BorderLayout, GridLayout, BoxLayout, ...