Class LayoutUtil
- Direct Known Subclasses:
GuiUtils
- Author:
- IDV development team
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Insets
2 pixel insetstatic final Insets
5 pixel insetstatic int
Set this to define your own anchor in the doLayout routines.static int[]
Use this to define your own column fills (i.e., horizontal expansion of the elements in the gribag).static int
Set this to define your own fill in the doLayout routines.static Insets
If you want to change the insets used in the doLayout routines you can set this and the routine will use the value and then set it to null.static final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
All of the WT_ members are used to define the column and row weights for the doLayout routines.static final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final double[]
doLayout weightsstatic final Insets
A 0 insetFields inherited from class ucar.unidata.util.MenuUtil
MENU_SEPARATOR
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JPanel
Creates a JPanel and does a BorderLayout SOUTH of the given componentstatic JPanel
Creates a JPanel and does a BorderLayout CENTER of the given componentstatic JPanel
centerBottom
(Component center, Component bottom) Creates a JPanel and does a BorderLayout CENTER/SOUTH of the given componentsstatic JPanel
centerRight
(Component center, Component right) Creates a JPanel and does a BorderLayout of the given componentsstatic JPanel
Do a grid layout with the number of columnsstatic JPanel
This does a column oriented grid bag layout.static JPanel
This does a column oriented grid bag layout.static JPanel
This does a column oriented grid bag layout.static JPanel
doLayout
(JPanel parentContainer, Component[] components, int numberOfColumns, double[] weightsX, double[] weightsY) This does a column oriented grid bag layout.static JPanel
doLayout
(JPanel parentContainer, Component[] components, int numberOfColumns, double[] weightsX, double[] weightsY, Hashtable anchors, Hashtable fills, Insets insets) This does a column oriented grid bag layout.static Component
filler()
A utility for having fillers in layout.static JComponent
filler
(int width, int height) A utility for having fillers in layout.static Component[]
getComponentArray
(List listOfComponents) A utility to convert the listOfComponents into a Component arraystatic JPanel
Do a grid layout with the number of columnsstatic JPanel
Do a grid layout with the number of columnsstatic JPanel
Do a horizontal layout of the given components.static JPanel
Do a horizontal layout of the given components.static JPanel
Do a horizontal layout of the given components.static JPanel
Do a horizontal layout of the given components with the given spacing.static JPanel
Do a horizontal layout of the given components.static JPanel
Do a horizontal layout of the given components with the given spacing.static JPanel
Do a horizontal layout of the given components.static JPanel
Do a horizontal layout of the given components.static JPanel
Do a horizontal layout of the given components.static JPanel
Do a horizontal layout of the given components.static JPanel
Do a horizontal layout of the given components.static JComponent
hfill
(JComponent comp) Wrap the component so that it only expands horizontally, not verticallystatic JPanel
Create a new JPanel and add the given components to it using a FlowLayout.static JPanel
Create a new JPanel and add the given components to it using a FlowLayout.static JPanel
Do a horizontal grid layout of the given componentsstatic JPanel
Do a horizontal grid layout of the given componentsstatic JPanel
Do a horizontal grid layout of the given componentsstatic JPanel
Inset the given component by the given insetSize, both horizontally and vertically.static JPanel
Inset the given component by the given insetSize for horizontally and vertically.static JPanel
Inset the given component by the given insets.static JPanel
Inset the given component, adding it into the given parent container, by the given insetSize, both horizontally and vertically.static JPanel
Creates a JPanel and does a BorderLayout.WEST of the given componentstatic JPanel
leftCenter
(Component left, Component center) Creates a JPanel and does a BorderLayout of the given componentsstatic JPanel
leftCenterRight
(Component left, Component center, Component right) Creates a JPanel and does a BorderLayout of the given componentsstatic JPanel
Creates a JPanel and does a BorderLayout of the given componentsstatic JPanel
This places the given components in a vertical orientation, left aligned.static JPanel
Creates a JPanel and does a BorderLayout of the given componentsstatic JPanel
Do a grid layout with the number of rowsstatic JPanel
Do a grid layout with the number of rowsstatic void
Sets the anchor to bottom for doLayoutstatic void
Sets the anchor to top for doLayoutstatic void
setHFill()
Turns on component horizontal fill for the doLayout routinestatic void
Turns off component fill for the doLayout routinestatic List
static JPanel
Creates a JPanel and does a BorderLayout-NORTH of the given componentstatic JPanel
Creates a JPanel and does a BorderLayout NORTH/BOTTOM of the given componentsstatic JPanel
Creates a JPanel and does a BorderLayout NORTH/CENTER of the given componentsstatic JPanel
topCenterBottom
(Component top, Component center, Component bottom) Creates a JPanel and does a BorderLayout of the given componentsstatic JPanel
Creates a JPanel and does a BorderLayout-NORTH of the given componentstatic JPanel
Layout the given components vertically.static JPanel
Layout the given components vertically.static JPanel
Layout the given components vertically.static JPanel
Layout the given components vertically.static JPanel
Layout the given components vertically.static JPanel
Layout the given components vertically.static JPanel
Layout the given components vertically.static JPanel
Do a single column grid layout of the componentsstatic JPanel
Do a single column grid layout of the componentsstatic JPanel
Wrap the given component.static JPanel
Wrap the given component, aligning it to the left.Methods inherited from class ucar.unidata.util.MenuUtil
findMethod, makeCheckboxMenuItem, makeCheckboxMenuItem, makeMenu, makeMenu, makeMenuItem, makeMenuItem, makeMenuItem, makeMenuItems, makePopupMenu, makePopupMenu, showPopupMenu, typesMatch
-
Field Details
-
tmpInsets
If you want to change the insets used in the doLayout routines you can set this and the routine will use the value and then set it to null. I know, I know, it isn't thread safe but... -
INSETS_5
5 pixel inset -
INSETS_2
2 pixel inset -
tmpColFills
public static int[] tmpColFillsUse this to define your own column fills (i.e., horizontal expansion of the elements in the gribag). Will be set to null after use. Not thread safe but... -
tmpAnchor
public static int tmpAnchorSet this to define your own anchor in the doLayout routines. Will get reset after use. Not thread safe. You can also callsetAnchorBottom()
andsetAnchorTop()
for changing the anchor. -
tmpFill
public static int tmpFillSet this to define your own fill in the doLayout routines. Will get reset after use. Not thread safe. You can also callsetNoFill()
andsetHFill()
for doing no fill and horizontal fill. -
ZERO_INSETS
A 0 inset -
WT_Y
public static final double[] WT_YAll of the WT_ members are used to define the column and row weights for the doLayout routines. They are double arrays, typically one for each col or row, that hold either a 1 or a 0. The "Y" and "N" implies YES or NO, i.e., does the corresponding row/column get weight (Y) or not get weight (N).So for example, if you wanted to have no stretchiness in the first column and put all of the stretchiness into the second column you would use:
WT_NY
Note, you can pass in your own double arrays to doLayout. These are just here for convenience.
-
WT_YY
public static final double[] WT_YYdoLayout weights -
WT_YYY
public static final double[] WT_YYYdoLayout weights -
WT_N
public static final double[] WT_NdoLayout weights -
WT_NN
public static final double[] WT_NNdoLayout weights -
WT_NNN
public static final double[] WT_NNNdoLayout weights -
WT_YN
public static final double[] WT_YNdoLayout weights -
WT_YYN
public static final double[] WT_YYNdoLayout weights -
WT_YNYN
public static final double[] WT_YNYNdoLayout weights -
WT_NYNYN
public static final double[] WT_NYNYNdoLayout weights -
WT_NY
public static final double[] WT_NYdoLayout weights -
WT_NYN
public static final double[] WT_NYNdoLayout weights -
WT_YNY
public static final double[] WT_YNYdoLayout weights -
WT_NYY
public static final double[] WT_NYYdoLayout weights -
WT_YNN
public static final double[] WT_YNNdoLayout weights -
WT_NNY
public static final double[] WT_NNYdoLayout weights -
WT_NNNY
public static final double[] WT_NNNYdoLayout weights -
WT_NNYN
public static final double[] WT_NNYNdoLayout weights -
WT_NNYNY
public static final double[] WT_NNYNYdoLayout weights -
WT_NNYNYNY
public static final double[] WT_NNYNYNYdoLayout weights -
WT_NYNY
public static final double[] WT_NYNYdoLayout weights
-
-
Constructor Details
-
LayoutUtil
public LayoutUtil()
-
-
Method Details
-
setNoFill
public static void setNoFill()Turns off component fill for the doLayout routine -
hfill
Wrap the component so that it only expands horizontally, not vertically- Parameters:
comp
- The component- Returns:
- The wrapped component
-
setHFill
public static void setHFill()Turns on component horizontal fill for the doLayout routine -
setAnchorBottom
public static void setAnchorBottom()Sets the anchor to bottom for doLayout -
setAnchorTop
public static void setAnchorTop()Sets the anchor to top for doLayout -
inset
Inset the given component by the given insetSize, both horizontally and vertically.- Parameters:
c
- The component to wrapinsetSize
- Horizontal and vertical inset- Returns:
- A JPanel that contains the given component inset the specified amount.
-
inset
Inset the given component by the given insetSize for horizontally and vertically.- Parameters:
c
- The component to wrapinsetSizeHor
- Inset horizontalinsetSizeVert
- Inset vertical- Returns:
- A JPanel that contains the given component inset the specified amount.
-
inset
Inset the given component by the given insets.- Parameters:
c
- The component to wrapinsets
- The insets- Returns:
- A JPanel that contains the given component inset the specified amount.
-
wrapLeft
Wrap the given component, aligning it to the left. It won't expand the component.- Parameters:
c
- The component to wrap- Returns:
- The wrapper
-
wrap
Wrap the given component. This won't expand the component. Use this when you want to place a component and not expand it.- Parameters:
c
- The component to wrap- Returns:
- The wrapper
-
hflow
Create a new JPanel and add the given components to it using a FlowLayout.- Parameters:
components
- The components to layout- Returns:
- The new JPanel
-
hflow
Create a new JPanel and add the given components to it using a FlowLayout.- Parameters:
components
- The components to layouthgap
- Horizontal spacingvgap
- Vertical spacing- Returns:
- The new JPanel
-
hgrid
Do a horizontal grid layout of the given components- Parameters:
comp1
- comp1comp2
- comp2_- Returns:
- The new JPanel holding the given components
-
hgrid
Do a horizontal grid layout of the given components- Parameters:
components
- The components to layout- Returns:
- The new JPanel holding the given components
-
hgrid
Do a horizontal grid layout of the given components- Parameters:
components
- The components to layoutspace
- The spacing- Returns:
- The new JPanel holding the given components
-
vgrid
Do a single column grid layout of the components- Parameters:
components
- The components to layout- Returns:
- The new JPanel
-
vgrid
Do a single column grid layout of the components- Parameters:
panel
- The panel to add tocomponents
- The components to layoutspace
- The spacing- Returns:
- The panel
-
rowGrid
Do a grid layout with the number of rows- Parameters:
comps
- Components to layoutrows
- Number of rows- Returns:
- The new panel
-
rowGrid
Do a grid layout with the number of rows- Parameters:
components
- Components to layoutrows
- Number of rows- Returns:
- The new panel
-
colGrid
Do a grid layout with the number of columns- Parameters:
components
- Components to layoutcols
- Number of cols- Returns:
- The new panel
-
grid
Do a grid layout with the number of columns- Parameters:
components
- Components to layoutrows
- Number of rows (0 implies not fixed)cols
- Number of cols (0 implies not fixed)- Returns:
- The new panel
-
grid
Do a grid layout with the number of columns- Parameters:
components
- Components to layoutrows
- Number of rows (0 implies not fixed)cols
- Number of cols (0 implies not fixed)space
- Spacing- Returns:
- The new panel
-
inset
Inset the given component, adding it into the given parent container, by the given insetSize, both horizontally and vertically.- Parameters:
parent
- The panel to put the component in.c
- The component to wrapinsetSize
- Horizontal and vertical inset- Returns:
- A JPanel that contains the given component inset the specified amount.
-
doLayout
This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns.- Parameters:
components
- List ofComponent
s to layoutnumberOfColumns
- How many columns in the grid layouthinset
- hor. insetvinset
- vert. inset- Returns:
- THe new panel
-
getComponentArray
A utility to convert the listOfComponents into a Component array- Parameters:
listOfComponents
- List of Components- Returns:
- Component array
-
doLayout
public static JPanel doLayout(List components, int numberOfColumns, double[] weightsX, double[] weightsY) This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns.- Parameters:
components
- The components to layoutnumberOfColumns
- How many columns in the grid layoutweightsX
- Defines how much weight to give to each column width. If there are more columns than weights then we use the last weight.weightsY
- Defines how much weight to give to each row height. If there are more rows than weights then we use the last weight.- Returns:
- New panel
-
doLayout
public static JPanel doLayout(Component[] components, int numberOfColumns, double[] weightsX, double[] weightsY) This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns.- Parameters:
components
- The components to layoutnumberOfColumns
- How many columns in the grid layoutweightsX
- Defines how much weight to give to each column width. If there are more columns than weights then we use the last weight.weightsY
- Defines how much weight to give to each row height. If there are more rows than weights then we use the last weight.- Returns:
- New panel
-
doLayout
public static JPanel doLayout(JPanel parentContainer, Component[] components, int numberOfColumns, double[] weightsX, double[] weightsY) This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns.- Parameters:
parentContainer
- The container to add components to. May be null.components
- The components to layoutnumberOfColumns
- How many columns in the grid layoutweightsX
- Defines how much weight to give to each column width. If there are more columns than weights then we use the last weight.weightsY
- Defines how much weight to give to each row height. If there are more rows than weights then we use the last weight.- Returns:
- New panel
-
vbox
Layout the given components vertically.- Parameters:
c1
- Component 1c2
- Component 2- Returns:
- The new container of the components.
-
vbox
Layout the given components vertically.- Parameters:
c1
- Component 1c2
- Component 2c3
- Component 3- Returns:
- The new container of the components.
-
vbox
Layout the given components vertically.- Parameters:
c1
- Component 1c2
- Component 2c3
- Component 3c4
- Component 4- Returns:
- The new container of the components.
-
vbox
Layout the given components vertically.- Parameters:
c1
- Component 1c2
- Component 2c3
- Component 3c4
- Component 4- Returns:
- The new container of the components.
-
vbox
Layout the given components vertically.- Parameters:
components
- The components- Returns:
- The new container of the components.
-
toList
-
vbox
Layout the given components vertically.- Parameters:
components
- The components- Returns:
- The new container of the components.
-
vbox
Layout the given components vertically.- Parameters:
panel
- The panel to put the components in if on-null.components
- The components- Returns:
- The given panel if non-null, else the newly create panel.
-
leftVbox
This places the given components in a vertical orientation, left aligned.- Parameters:
components
- The components- Returns:
- The new container of the components.
-
hbox
Do a horizontal layout of the given components with the given spacing.- Parameters:
c1
- Component 1c2
- Component 2spacing
- Inter component spacing- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components with the given spacing.- Parameters:
c1
- Component 1c2
- Component 2c3
- Component 3spacing
- Inter component spacing- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
c1
- Component 1c2
- Component 2- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
c1
- Component 1c2
- Component 2c3
- Component 3- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
c1
- Component 1c2
- Component 2c3
- Component 3c4
- Component 4- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
components
- The componentsspacing
- The spacing- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
components
- The components- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
components
- The components- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
components
- The componentsspacing
- _more_- Returns:
- The new container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
panel
- The panel to use or, if null, we'll create a new on.components
- The components- Returns:
- The container of the components
-
hbox
Do a horizontal layout of the given components.- Parameters:
panel
- The panel to use or, if null, we'll create a new on.components
- The componentsspace
- SPacing to use- Returns:
- The container of the components
-
doLayout
public static JPanel doLayout(JPanel parentContainer, Component[] components, int numberOfColumns, double[] weightsX, double[] weightsY, Hashtable anchors, Hashtable fills, Insets insets) This does a column oriented grid bag layout. It will layout the given components in a grid with the given number of columns. It is probably good to read up a bit on GridBagLayoutThe weights define how much weight or spacing to give to the width of each column and the height of each row.
To define the anchor value, i.e., how to fill a component in its grid square, you can either set the global static member
tmpAnchor
or, for individual Components you can use the anchors table to provide a mapping from Component to an Integer object holding the anchor value.To define the fill value, i.e., how a component expands in its grid square, you can either set the global static member
tmpFill
or, for individual Components you can use the fills table to provide a mapping from Component to an Integer object holding the fill value.If insets is non-null it will use those insets for the spacing in the grid. else if the static member tmpInsets is non-null then it will use those values and then set tmpInsets to null. Else it uses DFLT_INSETS, which is 0 spacing.
- Parameters:
parentContainer
- The container to add components to. May be null.components
- The components to layoutnumberOfColumns
- How many columns in the grid layoutweightsX
- Defines how much weight to give to each column width. If there are more columns than weights then we use the last weight.weightsY
- Defines how much weight to give to each row height. If there are more rows than weights then we use the last weight.anchors
- Hashtable that maps Component to the Integer which defines the component anchorfills
- Hashtable that maps Component to the Integer which defines the component fillinsets
- The insets to use in the grid- Returns:
- The parentContainer or the new panel if parentContainer is null
-
topLeft
Creates a JPanel and does a BorderLayout-NORTH of the given component- Parameters:
top
- The component to place- Returns:
- The new JPanel
-
top
Creates a JPanel and does a BorderLayout-NORTH of the given component- Parameters:
top
- The component to place- Returns:
- The new JPanel
-
left
Creates a JPanel and does a BorderLayout.WEST of the given component- Parameters:
left
- The component to place- Returns:
- The new JPanel
-
topCenter
Creates a JPanel and does a BorderLayout NORTH/CENTER of the given components- Parameters:
top
- The top componentcenter
- The center component- Returns:
- The new JPanel
-
topBottom
Creates a JPanel and does a BorderLayout NORTH/BOTTOM of the given components- Parameters:
top
- The top componentbottom
- The bottom component- Returns:
- The new JPanel
-
centerBottom
Creates a JPanel and does a BorderLayout CENTER/SOUTH of the given components- Parameters:
center
- The center componentbottom
- The bottom component- Returns:
- The new JPanel
-
bottom
Creates a JPanel and does a BorderLayout SOUTH of the given component- Parameters:
bottom
- The bottom component- Returns:
- The new JPanel
-
center
Creates a JPanel and does a BorderLayout CENTER of the given component- Parameters:
center
- The center component- Returns:
- The new JPanel
-
topCenterBottom
Creates a JPanel and does a BorderLayout of the given components- Parameters:
top
- The top component (may be null)center
- The center component (may be null)bottom
- The bottom component (may be null)- Returns:
- The new JPanel
-
leftRight
Creates a JPanel and does a BorderLayout of the given components- Parameters:
left
- The left componentright
- The right component- Returns:
- The new panel
-
leftCenterRight
Creates a JPanel and does a BorderLayout of the given components- Parameters:
left
- The left componentcenter
- The center componentright
- The right component- Returns:
- The new panel
-
centerRight
Creates a JPanel and does a BorderLayout of the given components- Parameters:
center
- The center componentright
- The right component- Returns:
- The new panel
-
right
Creates a JPanel and does a BorderLayout of the given components- Parameters:
right
- The right component- Returns:
- The new panel
-
leftCenter
Creates a JPanel and does a BorderLayout of the given components- Parameters:
left
- The left componentcenter
- The center component- Returns:
- The new panel
-
filler
A utility for having fillers in layout. This just returns an empty JPanel but we have it as a method so calling code can be explicit in what they are intending.- Returns:
- Filler
-
filler
A utility for having fillers in layout. This just returns an empty JPanel but we have it as a method so calling code can be explicit in what they are intending.- Parameters:
width
- filler widthheight
- filler height- Returns:
- Filler
-