Java JTextArea copyFontAndMargins(final JTextArea target, final JComponent source)

Here you can find the source of copyFontAndMargins(final JTextArea target, final JComponent source)

Description

copy Font And Margins

License

Open Source License

Declaration

public static void copyFontAndMargins(final JTextArea target, final JComponent source) 

Method Source Code


//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));
        }
    }
}

Related

  1. attachSimpleUndoManager(JTextArea jta)
  2. blockUncomment(JTextArea scriptPanel)
  3. clearTextArea(JTextArea textArea)
  4. columns(JTextArea testString)
  5. commentSQL(JTextArea scriptPanel, String commentCharacter)
  6. createTabArea(JTextArea area, int width)
  7. display(JTextArea txtOutput, String text)
  8. estimatedRows(JTextArea text)
  9. fixTabKeys(JTextArea textArea)