code: private void determineInsetsAndAlignment() {
          borderInsets = new Insets(0, 0, 0, 0);
  
          //  The insets will only be updated for the edge the component will be
          //  diplayed on.
          //
          //  The X, Y alignment of the component is controlled by both the edge
          //  and alignment parameters
  
          if (edge == Edge.TOP) {
              borderInsets.top = component.getPreferredSize().height + gap;
              component.setAlignmentX(alignment);
              component.setAlignmentY(0.0f);
          } else if (edge == Edge.BOTTOM) {
              borderInsets.bottom = component.getPreferredSize().height + gap;
              component.setAlignmentX(alignment);
              component.setAlignmentY(1.0f);
          } else if (edge == Edge.LEFT) {
              borderInsets.left = component.getPreferredSize().width + gap;
              component.setAlignmentX(0.0f);
              component.setAlignmentY(alignment);
          } else if (edge == Edge.RIGHT) {
              borderInsets.right = component.getPreferredSize().width + gap;
              component.setAlignmentX(1.0f);
              component.setAlignmentY(alignment);
          }
  
          if (adjustInsets) {
              adjustBorderInsets();
          }
      }
docs: The insets need to be determined so they are included in the preferred
  size of the component the Border is attached to.
  
  The alignment of the component is determined here so it doesn't need
  to be recalculated every time the Border is painted.