Class GridBagLayout
Codename One port of the infamous GridBagLayout based on the Apache Harmony code. For new applications
we generally recommend a "native" Codename One layout such as com.codename1.ui.table.TableLayout
and recommend avoiding this layout. Its here for developers who are accustomed to it and need to port existing code.
Button button;
hi.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
//natural height, maximum width
c.fill = GridBagConstraints.HORIZONTAL;
button = new Button("Button 1");
c.weightx = 0.5;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
hi.addComponent(c, button);
button = new Button("Button 2");
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 1;
c.gridy = 0;
hi.addComponent(c, button);
button = new Button("Button 3");
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 2;
c.gridy = 0;
hi.addComponent(c, button);
button = new Button("Long-Named Button 4");
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 40; //make this component tall
c.weightx = 0.0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 1;
hi.addComponent(c, button);
button = new Button("5");
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0; //reset to default
c.weighty = 1.0; //request any extra vertical space
c.anchor = GridBagConstraints.PAGE_END; //bottom of space
c.insets = new Insets(10,0,0,0); //top padding
c.gridx = 1; //aligned with button 2
c.gridwidth = 2; //2 columns wide
c.gridy = 2; //third row
hi.addComponent(c, button);
-
Field Summary
FieldsModifier and TypeFieldDescriptiondouble[]int[]protected Hashtable<Component, GridBagConstraints> protected GridBagConstraintsprotected com.codename1.ui.layouts.GridBagLayoutInfoprotected static final intprotected static final intprotected static final intint[]double[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayoutComponent(Object constraints, Component comp, Container c) Some layouts can optionally track the addition of elements with meta-data that allows the user to "hint" on object positioning.protected voidadjustForGravity(GridBagConstraints constraints, Rectangle r) protected voidarrangeGrid(Container parent) Returns the optional component constraintint[][]double[][]getPreferredSize(Container parent) Returns the container preferred sizevoidinvalidateLayout(Container target) voidlayoutContainer(Container parent) Layout the given parent container childrenprotected GridBagConstraintslookupConstraints(Component comp) voidRemoves the component from the layout this operation is only useful if the layout maintains references to components within itvoidsetConstraints(Component comp, GridBagConstraints constraints) Methods inherited from class Layout
cloneConstraint, equals, getChildrenInTraversalOrder, hashCode, isConstraintTracking, isOverlapSupported, obscuresPotential, overridesTabIndices, updateTabIndices
-
Field Details
-
MAXGRIDSIZE
protected static final int MAXGRIDSIZE- See Also:
-
MINSIZE
protected static final int MINSIZE- See Also:
-
PREFERREDSIZE
protected static final int PREFERREDSIZE- See Also:
-
columnWeights
public double[] columnWeights -
rowWeights
public double[] rowWeights -
columnWidths
public int[] columnWidths -
rowHeights
public int[] rowHeights -
comptable
-
defaultConstraints
-
layoutInfo
protected com.codename1.ui.layouts.GridBagLayoutInfo layoutInfo
-
-
Constructor Details
-
GridBagLayout
public GridBagLayout()
-
-
Method Details
-
addLayoutComponent
Description copied from class:LayoutSome layouts can optionally track the addition of elements with meta-data that allows the user to "hint" on object positioning.
Parameters
-
value: optional meta data information, like alignment orientation -
comp: the added component to the layout -
c: the parent container
- Overrides:
addLayoutComponentin classLayout
-
-
removeLayoutComponent
Description copied from class:LayoutRemoves the component from the layout this operation is only useful if the layout maintains references to components within it
Parameters
comp: the removed component from layout
- Overrides:
removeLayoutComponentin classLayout
-
getComponentConstraint
Description copied from class:LayoutReturns the optional component constraint
Parameters
comp: the component whose constraint should be returned
Returns
the optional component constraint
- Overrides:
getComponentConstraintin classLayout
-
setConstraints
-
invalidateLayout
-
getPreferredSize
Description copied from class:LayoutReturns the container preferred size
Parameters
parent: the parent container
Returns
the container preferred size
- Specified by:
getPreferredSizein classLayout
-
layoutContainer
Description copied from class:LayoutLayout the given parent container children
Parameters
parent: the given parent container
- Specified by:
layoutContainerin classLayout
-
getLayoutDimensions
public int[][] getLayoutDimensions() -
getLayoutWeights
public double[][] getLayoutWeights() -
arrangeGrid
-
lookupConstraints
-
adjustForGravity
-