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.Component
s - 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.UiProvider
s; java.lang.String
s - The string is added as a JLabel
; javax.swing.Action
s - The action is added as a KongaButton
. javax.swing.Icon
s - The icon is added as a JLabel
.
See the following methods for how to further customize this behavior:
- {@link #forString(String)} - customize how
String
s are added; - {@link #forAction(Action)} - customize how
Action
s are added; - {@link #forIcon(Icon)} - customize how
Icon
s are added; - {@link #forObject(Object)} - customize how
Object
s of unknown types are added; - {@link #isAutomaticallyWrappingScrollables()} - customize how
Scrollable
Component
s 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