Java JComponent Padding addPadding(JComponent comp, int topbottom, int leftright)

Here you can find the source of addPadding(JComponent comp, int topbottom, int leftright)

Description

Adds padding to a component by creating a Compound Border using the current border and a new empty border with the specified side widths.

License

Open Source License

Parameter

Parameter Description
comp Component to Pad
topbottom Top and Bottom Padding
leftright Left and Right Padding

Declaration

public static void addPadding(JComponent comp, int topbottom, int leftright) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.BorderFactory;
import javax.swing.JComponent;

public class Main {
    /**//from   w ww  . j a  va  2s.c o  m
     * Adds padding to a component by creating a Compound Border using
     * the current border and a new empty border with the specified side widths.
     *
     * @param comp   Component to Pad
     * @param top    Top Padding
     * @param right  Right Padding
     * @param bottom Bottom Padding
     * @param left   Left Padding
     */
    public static void addPadding(JComponent comp, int top, int right, int bottom, int left) {
        comp.setBorder(BorderFactory.createCompoundBorder(comp.getBorder(),
                BorderFactory.createEmptyBorder(top, left, bottom, right)));
    }

    /**
     * Adds padding to a component by creating a Compound Border using
     * the current border and a new empty border with the specified side widths.
     *
     * @param comp      Component to Pad
     * @param topbottom Top and Bottom Padding
     * @param leftright Left and Right Padding
     */
    public static void addPadding(JComponent comp, int topbottom, int leftright) {
        addPadding(comp, topbottom, leftright, topbottom, leftright);
    }

    /**
     * Adds padding to a component by creating a Compound Border using
     * the current border and a new empty border with the specified side widths.
     *
     * @param comp Component to Pad
     * @param all  Padding for All Sides
     */
    public static void addPadding(JComponent comp, int all) {
        addPadding(comp, all, all, all, all);
    }
}

Related

  1. makePaddedPanel(JComponent aComponent, Insets aInsets)
  2. pad(JComponent component, int w, int h)
  3. paint(JComponent jc, int padding)
  4. setComponentHeight(JComponent setme, JComponent getme, int padding)