Here you can find the source of copyFontAndMargins(final JTextArea target, final JComponent source)
public static void copyFontAndMargins(final JTextArea target, final JComponent source)
//package com.java2s; // Licensed under the MIT license. See License.txt in the project root. import javax.swing.JComponent; import javax.swing.JTextArea; import javax.swing.border.Border; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import java.awt.Insets; public class Main { public static void copyFontAndMargins(final JTextArea target, final JComponent source) { final Insets insets = source.getInsets(); target.setFont(source.getFont()); target.setMargin(insets);//w w w. ja v a 2s .c o m } public static void setMargin(final JComponent component, final int eachSide) { final Insets insets = new Insets(eachSide, eachSide, eachSide, eachSide); setMargin(component, insets); } public static void setMargin(final JComponent component, final Insets newMargin) { final Border currentBorder = component.getBorder(); final Border empty = new EmptyBorder(newMargin.top, newMargin.left, newMargin.bottom, newMargin.right); if (currentBorder == null || currentBorder instanceof EmptyBorder) { component.setBorder(empty); } else if (currentBorder instanceof CompoundBorder) { final CompoundBorder current = (CompoundBorder) currentBorder; final Border insideBorder = current.getInsideBorder(); component.setBorder(new CompoundBorder(empty, insideBorder)); } else { component.setBorder(new CompoundBorder(empty, currentBorder)); } } }