question: public void paintBorder ( Component c , Graphics g , int x , int y , int width , int height ) { Border border = getBorder ( ) ; String title = getTitle ( ) ; if ( ( title != null ) && ! title . isEmpty ( ) ) { int edge = ( border instanceof TitledBorder ) ? 0 : EDGE_SPACING ; JLabel label = getLabel ( c ) ; Dimension size = label . getPreferredSize ( ) ; Insets insets = getBorderInsets ( border , c , new Insets ( 0 , 0 , 0 , 0 ) ) ; int borderX = x + edge ; int borderY = y + edge ; int borderW = width - edge - edge ; int borderH = height - edge - edge ; int labelY = y ; int labelH = size . height ; int position = getPosition ( ) ; switch ( position ) { case ABOVE_TOP : insets . left = 0 ; insets . right = 0 ; borderY += labelH - edge ; borderH -= labelH - edge ; break ; case TOP : insets . top = edge + insets . top / 2 - labelH / 2 ; if ( insets . top < edge ) { borderY -= insets . top ; borderH += insets . top ; } else { labelY += insets . top ; } break ; case BELOW_TOP : labelY += insets . top + edge ; break ; case ABOVE_BOTTOM : labelY += height - labelH - insets . bottom - edge ; break ; case BOTTOM : labelY += height - labelH ; insets . bottom = edge + ( insets . bottom - labelH ) / 2 ; if ( insets . bottom < edge ) { borderH += insets . bottom ; } else { labelY -= insets . bottom ; } break ; case BELOW_BOTTOM : insets . left = 0 ; insets . right = 0 ; labelY += height - labelH ; borderH -= labelH - edge ; break ; } insets . left += edge + TEXT_INSET_H ; insets . right += edge + TEXT_INSET_H ; int labelX = x ; int labelW = width - insets . left - insets . right ; if ( labelW > size . width ) { labelW = size . width ; } switch ( getJustification ( c ) ) { case LEFT : labelX += insets . left ; break ; case RIGHT : labelX += width - insets . right - labelW ; break ; case CENTER : labelX += ( width - labelW ) / 2 ; break ; } if ( border != null ) { if ( ( position != TOP ) && ( position != BOTTOM ) ) { border . paintBorder ( c , g , borderX , borderY , borderW , borderH ) ; } else { Graphics g2 = g . create ( ) ; if ( g2 instanceof Graphics2D ) { Graphics2D g2d = ( Graphics2D ) g2 ; Path2D path = new Path2D . Float ( ) ; path . append ( new Rectangle ( borderX , borderY , borderW , labelY - borderY ) , false ) ; path . append ( new Rectangle ( borderX , labelY , labelX - borderX - TEXT_SPACING , labelH ) , false ) ; path . append ( new Rectangle ( labelX + labelW + TEXT_SPACING , labelY , borderX - labelX + borderW - labelW - TEXT_SPACING , labelH ) , false ) ; path . append ( new Rectangle ( borderX , labelY + labelH , borderW , borderY - labelY + borderH - labelH ) , false ) ; g2d . clip ( path ) ; } border . paintBorder ( c , g2 , borderX , borderY , borderW , borderH ) ; g2 . dispose ( ) ; } } g . translate ( labelX , labelY ) ; label . setSize ( labelW , labelH ) ; label . paint ( g ) ; g . translate ( - labelX , - labelY ) ; } else if ( border != null ) { border . paintBorder ( c , g , x , y , width , height ) ; } }
target:  Paints the border for the specified component with the specified position and size.