Java Utililty Methods Swing BorderLayout

List of utility methods to do Swing BorderLayout

Description

The list of methods to do Swing BorderLayout are organized into topic(s).

Method

ComponentaddBorders(Component content)
add Borders
JPanel panel = new JPanel();
BoxLayout boxLayout1 = new BoxLayout(panel, BoxLayout.Y_AXIS);
panel.setLayout(boxLayout1);
panel.setBackground(CYAN);
JPanel topPanel = new JPanel();
topPanel.setPreferredSize(new Dimension((int) content.getPreferredSize().getWidth() + 5, 5));
topPanel.setLayout(new BorderLayout());
topPanel.setBackground(BLUE);
...
JPaneladdToPanel(JPanel panel, JComponent centerComponent, JComponent arrangedComponent, String borderLayoutConstraint)
add To Panel
panel.add(centerComponent, BorderLayout.CENTER);
panel.add(arrangedComponent, borderLayoutConstraint);
return panel;
JPaneladdToVerticalBorderLayout(JComponent north, JComponent center, JComponent south)
add To Vertical Border Layout
JPanel panel = new JPanel(new BorderLayout());
if (north != null) {
    panel.add(north, BorderLayout.NORTH);
if (center != null) {
    panel.add(center, BorderLayout.CENTER);
if (south != null) {
...
JPanelcreateBorderLayoutPane(Object... args)
create Border Layout Pane
if (args.length % 2 != 0) {
    throw new IllegalArgumentException("Illegal Arguments");
BorderLayout layout = new BorderLayout();
Object maybeHgap = args[args.length - 2];
Object maybeVgap = args[args.length - 1];
boolean hasGap = false;
if (maybeHgap instanceof Integer && maybeVgap instanceof Integer) {
...
JPanelcreateBox(Border border, Component center, Component north)
create Box
return createBox(border, center, north, null, null, null);
JPanelcreatePanel(Component comp, boolean setBorder, int borderType)
create Panel
JPanel panel = new JPanel(new BorderLayout());
panel.add(comp, BorderLayout.CENTER);
if (setBorder)
    setBorder(panel, borderType);
return panel;
JPanelcreatePanel(JComponent centerComponent, JComponent placedComponent, String borderLayoutConstraint)
create Panel
JPanel panel = createPanel();
return addToPanel(panel, centerComponent, placedComponent, borderLayoutConstraint);
JComponentlayoutCompactHorizontal(JComponent... list)
Compact horizontal layout.
JComponent last = list[list.length - 1];
for (int i = list.length - 2; i >= 0; i--) {
    JPanel p = new JPanel(new BorderLayout());
    p.add(list[i], BorderLayout.WEST);
    p.add(last, BorderLayout.EAST);
    last = p;
return last;
...
JComponentlayoutCompactVertical(JComponent... list)
layout Compact Vertical
JComponent last = list[list.length - 1];
for (int i = list.length - 2; i >= 0; i--) {
    JPanel p = new JPanel(new BorderLayout());
    p.add(list[i], BorderLayout.NORTH);
    p.add(last, BorderLayout.SOUTH);
    last = p;
return last;
...
JPanelmakeBorderPanel(int topMargin, int leftMargin, int bottomMargin, int rightMargin)
Make a JPanel with a BorderLayout ; set the border to the given margins.
JPanel result = makeBorderPanel();
result.setBorder(BorderFactory.createEmptyBorder(topMargin, leftMargin, bottomMargin, rightMargin));
return result;