Here you can find the source of setTextComponentMargins(JTextComponent component)
public static void setTextComponentMargins(JTextComponent component)
//package com.java2s; //License from project: Open Source License import java.awt.Insets; import javax.swing.text.JTextComponent; public class Main { private static final int DEFAULT_TEXT_COMPONENT_VERTICAL_MARGIN = 2; private static final int DEFAULT_TEXT_COMPONENT_HORIZONAL_MARGIN = 4; public static void setTextComponentMargins(JTextComponent component) { setTextComponentMargins(component, DEFAULT_TEXT_COMPONENT_VERTICAL_MARGIN, DEFAULT_TEXT_COMPONENT_HORIZONAL_MARGIN); }//from w ww .ja v a 2 s .c om public static void setTextComponentMargins(JTextComponent component, int vertical, int horizontal) { Insets margins = component.getMargin(); margins.set(Math.max(vertical, margins.top), Math.max(horizontal, margins.left), Math.max(vertical, margins.bottom), Math.max(horizontal, margins.right)); component.setMargin(margins); } }