Package io.github.jonestimd.swing.layout
Class GridBagBuilder
- java.lang.Object
-
- io.github.jonestimd.swing.layout.GridBagBuilder
-
public class GridBagBuilder extends java.lang.ObjectA form builder that simplifies usage ofGridBagLayout. The initial constraints are as follows(gridx, gridy) =(0, 0)fill = HORIZONTALweightx, weighty =1.0anchor = WEST
GridBagFormulawhen each component is added.By default, the following components are automatically wrapped in a
JScrollPane. Automatic wrapping of components inJScrollPanecan be enabled/disabled usinguseScrollPane(Class)andnoUseScrollPane(Class)JTableJListJTextArea
-
-
Field Summary
Fields Modifier and Type Field Description static intRELATED_GAPstatic intUNRELATED_GAP
-
Constructor Summary
Constructors Constructor Description GridBagBuilder(java.awt.Container container, java.util.ResourceBundle bundle, java.lang.String resourcePrefix)Create a new builder using 2 columns and the defaultGridBagFormulas.GridBagBuilder(java.awt.Container container, java.util.ResourceBundle bundle, java.lang.String resourcePrefix, int columns)Create a new builder using the defaultGridBagFormulas.GridBagBuilder(java.awt.Container container, java.util.ResourceBundle bundle, java.lang.String resourcePrefix, int columns, java.util.Map<java.lang.Class<?>,GridBagFormula> fieldConstraints)Create a new builder using specificGridBagFormulas.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends javax.swing.JComponent>
Tappend(java.lang.String labelKey, T field)Append a labeled component to the form.<T extends javax.swing.JComponent>
Tappend(java.lang.String labelKey, T field, GridBagFormula formula)Append a labeled component to the form.voidappend(javax.swing.JRadioButton... buttons)Append a group of radio buttons in a horizontal box.<T extends javax.swing.JComponent>
Tappend(T field)Append an unlabeled component to the form.<T extends javax.swing.JComponent>
Tappend(T field, GridBagFormula formula)Append an unlabeled component to the form.javax.swing.JLabelgetLastLabel()GridBagBuilderinsets(int top, int left, int bottom, int right)Set the insets for the next component.voidnextCell()Move to the next cell.GridBagBuildernoUseScrollPane(java.lang.Class<? extends javax.swing.JComponent> componentClass)Disable automatic wrapping of instances of the class in aJScrollPane.<T extends javax.swing.JComponent>
Toverlay(T field)Add a component in the same location as the previous component.GridBagBuilderrelatedGap()Use the horizontal and verticalRELATED_GAPfor the next component.GridBagBuildersetConstraints(java.lang.Class<?> componentClass, GridBagFormula constraints)GridBagBuilderunrelatedVerticalGap()Use the verticalUNRELATED_GAPand horizontalRELATED_GAPfor the next component.GridBagBuilderuseScrollPane(java.lang.Class<? extends javax.swing.JComponent> componentClass)Automatically wrap instances of the class in aJScrollPane.
-
-
-
Field Detail
-
RELATED_GAP
public static final int RELATED_GAP
- See Also:
- Constant Field Values
-
UNRELATED_GAP
public static final int UNRELATED_GAP
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GridBagBuilder
public GridBagBuilder(java.awt.Container container, java.util.ResourceBundle bundle, java.lang.String resourcePrefix)Create a new builder using 2 columns and the defaultGridBagFormulas.- Parameters:
container- the form containerbundle- provides label textresourcePrefix- prefix for resource bundle keys- See Also:
FormElement
-
GridBagBuilder
public GridBagBuilder(java.awt.Container container, java.util.ResourceBundle bundle, java.lang.String resourcePrefix, int columns)Create a new builder using the defaultGridBagFormulas.- Parameters:
container- the form containerbundle- provides label textresourcePrefix- prefix for resource bundle keyscolumns- the number of grid columns
-
GridBagBuilder
public GridBagBuilder(java.awt.Container container, java.util.ResourceBundle bundle, java.lang.String resourcePrefix, int columns, java.util.Map<java.lang.Class<?>,GridBagFormula> fieldConstraints)Create a new builder using specificGridBagFormulas.- Parameters:
container- the form containerbundle- provides label textresourcePrefix- prefix for resource bundle keyscolumns- the number of grid columnsfieldConstraints- map of component class toGridBagFormula
-
-
Method Detail
-
useScrollPane
public GridBagBuilder useScrollPane(java.lang.Class<? extends javax.swing.JComponent> componentClass)
Automatically wrap instances of the class in aJScrollPane.
-
noUseScrollPane
public GridBagBuilder noUseScrollPane(java.lang.Class<? extends javax.swing.JComponent> componentClass)
Disable automatic wrapping of instances of the class in aJScrollPane.
-
getLastLabel
public javax.swing.JLabel getLastLabel()
- Returns:
- the most recently created field label
-
setConstraints
public GridBagBuilder setConstraints(java.lang.Class<?> componentClass, GridBagFormula constraints)
-
relatedGap
public GridBagBuilder relatedGap()
Use the horizontal and verticalRELATED_GAPfor the next component.- Returns:
- this builder
-
unrelatedVerticalGap
public GridBagBuilder unrelatedVerticalGap()
Use the verticalUNRELATED_GAPand horizontalRELATED_GAPfor the next component.- Returns:
- this builder
-
insets
public GridBagBuilder insets(int top, int left, int bottom, int right)
Set the insets for the next component.- Returns:
- this builder
-
append
public <T extends javax.swing.JComponent> T append(java.lang.String labelKey, T field)Append a labeled component to the form.- Type Parameters:
T- the class of the component- Parameters:
labelKey- the resource key for the labelfield- the component- Returns:
- the component
-
append
public <T extends javax.swing.JComponent> T append(java.lang.String labelKey, T field, GridBagFormula formula)Append a labeled component to the form.- Type Parameters:
T- the class of the component- Parameters:
labelKey- the resource key for the labelfield- the componentformula- the constraints calculator for the component- Returns:
- the component
-
append
public <T extends javax.swing.JComponent> T append(T field)
Append an unlabeled component to the form.- Type Parameters:
T- the class of the component- Parameters:
field- the component- Returns:
- the component
-
append
public <T extends javax.swing.JComponent> T append(T field, GridBagFormula formula)Append an unlabeled component to the form.- Type Parameters:
T- the class of the component- Parameters:
field- the componentformula- the constraints calculator for the component- Returns:
- the component
-
overlay
public <T extends javax.swing.JComponent> T overlay(T field)
Add a component in the same location as the previous component.- Returns:
- the component
-
append
public void append(javax.swing.JRadioButton... buttons)
Append a group of radio buttons in a horizontal box.- Parameters:
buttons- the buttons to append
-
nextCell
public void nextCell()
Move to the next cell. If there are columns left in the row then moves to the next column. Otherwise, moves to the first column of the next row.
-
-