|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectjApp.BetterBoxLayout
public class BetterBoxLayout
Implements a layout quite similar to javax.swing.BoxLayout
, only better.
BetterBoxLay out can be used to lay out components in row or a column. In the following description horizontal (row) orientation is assumend. To understand how the vertical orientation works, just re-read the description and replace/swap column for row, width for height, horizontal for vertical etc. The following constants are used to set the orientation of the layout. These and other constants need to be combined and passed to the constructor to define the layout behaviour.
In the horizontal direction components are laid out in a row, one after another. Glue objects, struts and
rigid areas can be inserted, just like with a regular BoxLayout
.
Here is a short description of glue, struts and rigid areas, all of which are invisible objects:
The components minimum and maximums sizes are always observed.
If there are no glue objects then the components are resized in the horizontal direction as needed to fill the space available, (within the components minimum and maximum widths). When resising the components the relative widths of components (as defined by their preferred widths) are maintained as far as possible.
If there are glue objects and there is extra in the horizontal direction then the extra space is used to expand those glue objects evenly to fill the available space.
If there are no glue objects and the components cannot be stretched to fill the space available, then the extra space is added to the beginning and enf of the row.
The components minimum and maximums sizes are always observed.
Each components height is determined by its minimum, maximum, preferred or container's height depending on the passed to the constructor of layout manager:
In addtion to those the following flag can be used to ensure that no component will be higher than it's container.
A major difference from BetterBoxLayout
does NOT ignore invisible components (by default). If hidden components are NOT ignored then
hiding a component does NOT affect the layout. This is usually better behaviour because
otherwise the remaining (visible) buttons would move, which is (usually) poor UI practice. Disabling buttons is
of course often an option but there are many situation in which the preferred choise is hiding.
The following constant can be used tell the layout manager to ignore hidden (invisible) components.
Copyright: Copyright (c) 2004 Kusta Nyholm Oy
Field Summary | |
---|---|
static int |
CLIPPED_HEIGHT
Limit component height to container height |
static int |
CLIPPED_WIDTH
Limit component width to container width |
static int |
CONTAINER_HEIGHT
Use container height for component height |
static int |
CONTAINER_WIDTH
Use container widht for component height |
static int |
IGNORE_HIDDEN
Instruct layout manager to ignore hidden components |
static int |
MAXIMUM_HEIGHT
Maximise component height |
static int |
MAXIMUM_WIDTH
Maximise component width |
static int |
MINIMUM_HEIGHT
Mimimize component height |
static int |
MINIMUM_WIDTH
Mimimize component width |
static int |
PREFERRED_HEIGHT
Use component preferred height |
static int |
PREFERRED_WIDTH
Use component preferred width |
static int |
X_AXIS
Horizontal orientation |
static int |
Y_AXIS
Vertical orientation |
Constructor Summary | |
---|---|
BetterBoxLayout()
Creates a horizontal layout where components are their respective preferred sizes clipped to the container height. |
|
BetterBoxLayout(int flags)
Creates a layout based on the flags passed. |
Method Summary | |
---|---|
void |
addLayoutComponent(java.lang.String name,
java.awt.Component comp)
Not used by this layout manager. |
static javax.swing.JComponent |
createGlue()
Creates a glue object. |
static javax.swing.JPanel |
createHorizontalBox()
|
static javax.swing.JComponent |
createHorizontalGlue()
Creates a horizontal glue object. |
static javax.swing.JComponent |
createHorizontalStrut(int w)
Creates a horizontal strut object of a given width. |
static javax.swing.JComponent |
createRigidArea(int w,
int h)
Createas an invisible (transparent), space occupying, non resizable component of given width and height. |
static javax.swing.JPanel |
createVerticalBox()
|
static javax.swing.JComponent |
createVerticalGlue()
Creates a vertical glue object. |
static javax.swing.JComponent |
createVerticalStrut(int h)
Creates a vertical strut object of a given height. |
double |
getAlignmentY(java.awt.Component c)
|
void |
layoutContainer(java.awt.Container container)
Called by the AWT when the specified container needs to be laid out. |
java.awt.Dimension |
maximumSize(java.awt.Container container)
|
java.awt.Dimension |
minimumLayoutSize(java.awt.Container container)
|
java.awt.Dimension |
preferredLayoutSize(java.awt.Container container)
|
void |
removeLayoutComponent(java.awt.Component comp)
Not used by this layout manager. |
static void |
test()
Opens a few test windows to test/debug the layout manager. |
static void |
test1()
|
static void |
test2()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int X_AXIS
public static final int Y_AXIS
public static final int MINIMUM_HEIGHT
public static final int MINIMUM_WIDTH
public static final int PREFERRED_HEIGHT
public static final int PREFERRED_WIDTH
public static final int MAXIMUM_HEIGHT
public static final int MAXIMUM_WIDTH
public static final int CONTAINER_HEIGHT
public static final int CONTAINER_WIDTH
public static final int CLIPPED_HEIGHT
public static final int CLIPPED_WIDTH
public static final int IGNORE_HIDDEN
Constructor Detail |
---|
public BetterBoxLayout()
public BetterBoxLayout(int flags)
flags
- see class description for usage
java.lang.IllegalArgumentException
- if conflicting flags are detectedMethod Detail |
---|
public void addLayoutComponent(java.lang.String name, java.awt.Component comp)
addLayoutComponent
in interface java.awt.LayoutManager
name
- comp
- public void removeLayoutComponent(java.awt.Component comp)
removeLayoutComponent
in interface java.awt.LayoutManager
comp
- public java.awt.Dimension preferredLayoutSize(java.awt.Container container)
preferredLayoutSize
in interface java.awt.LayoutManager
public java.awt.Dimension minimumLayoutSize(java.awt.Container container)
minimumLayoutSize
in interface java.awt.LayoutManager
public java.awt.Dimension maximumSize(java.awt.Container container)
public double getAlignmentY(java.awt.Component c)
public void layoutContainer(java.awt.Container container)
layoutContainer
in interface java.awt.LayoutManager
container
- the container to lay out
java.awt.AWTError
- if a sharing situation is detected between the specified container and
one passed to this routine before.public static javax.swing.JComponent createGlue()
public static javax.swing.JComponent createHorizontalGlue()
public static javax.swing.JComponent createVerticalGlue()
public static javax.swing.JComponent createHorizontalStrut(int w)
w
- the width of the strut
public static javax.swing.JComponent createVerticalStrut(int h)
h
- the height of the strut
public static javax.swing.JComponent createRigidArea(int w, int h)
w
- the width of the rigid areah
- the height of the rigid area
public static javax.swing.JPanel createHorizontalBox()
public static javax.swing.JPanel createVerticalBox()
public static void test()
public static void test1()
public static void test2()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |