g BorderLayout: JPanel p = new JPanel(new BorderLayout(0, 10)); p.add(new JLabel("List of things:"), BorderLayout.NORTH); p.add(new JScrollPane(list), BorderLayout.CENTER); p.add(buttons, BorderLayout.SOUTH); // Using BorderLayoutBuilder: BorderLayoutBuilder layout = new BorderLayoutBuilder(0, 10); layout.north("List of things:").center(list).south(buttons); JComponent p = layout.container(); // Using BorderLayoutBuilder (2): BorderLayoutBuilder layout = new BorderLayoutBuilder(0, 10); layout.northToSouth("List of things:", list, buttons); JComponent p = layout.container();
BorderLayoutBuilder provides explicit methods for adding items to the respective layout position ( {@link #north(Object) north}, {@link #west(Object) west}, {@link #center(Object) center}, etc. Each method returns the
BorderLayoutBuilder itself, to allow for chained calls.
The adding methods takes an Object as input. The following types of objects are recognized by default:
java.awt.Components - The Component is added directly to the layout, unless it implements Scrollable in which case it is wrapped in a JScrollPane first; org.jitterbit.ui.UiProviders; java.lang.Strings - The string is added as a JLabel; javax.swing.Actions - The action is added as a KongaButton. javax.swing.Icons - The icon is added as a JLabel.
See the following methods for how to further customize this behavior:
- {@link #forString(String)} - customize how
Strings are added; - {@link #forAction(Action)} - customize how
Actions are added; - {@link #forIcon(Icon)} - customize how
Icons are added; - {@link #forObject(Object)} - customize how
Objects of unknown types are added; - {@link #isAutomaticallyWrappingScrollables()} - customize how
ScrollableComponents are added.
BorderLayoutBuilder also implements the {@link UiCanvas} interface. When used as aUiCanvas the displayed component is always added in the {@link #center(Object) center} position of the layout builder.
@author Torgil Zethson
@since 2.0.0