JPanel (boolean verticalOrientation, float childAlignment, Component... children) { JPanel panel = new JPanel(); int axis = verticalOrientation ? BoxLayout.Y_AXIS : BoxLayout.X_AXIS; panel.setLayout(new BoxLayout(panel, axis)); for (Component child : children) { panel.add(child, childAlignment); if (child instanceof JComponent jChild) { if (verticalOrientation) { jChild.setAlignmentX(childAlignment); } else { jChild.setAlignmentY(childAlignment); } } } return panel; }