Java JComponent Padding makePaddedPanel(JComponent aComponent, Insets aInsets)

Here you can find the source of makePaddedPanel(JComponent aComponent, Insets aInsets)

Description

make Padded Panel

License

Apache License

Declaration

private static JPanel makePaddedPanel(JComponent aComponent, Insets aInsets) 

Method Source Code


//package com.java2s;
/*/*from   w w  w  . j av  a2  s.com*/
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.swing.*;
import javax.swing.border.Border;

import java.awt.*;

public class Main {
    private static final Insets paddingInsideDialog = new Insets(5, 5, 5, 5);

    private static JPanel makePaddedPanel(JComponent aComponent, Insets aInsets) {
        return wrapWithBorder(aComponent,
                BorderFactory.createEmptyBorder(aInsets.top, aInsets.left, aInsets.bottom, aInsets.right));
    }

    private static JPanel makePaddedPanel(JComponent aComponent, boolean aTop, boolean aLeft, boolean aBottom,
            boolean aRight) {
        return wrapWithBorder(aComponent,
                BorderFactory.createEmptyBorder(aTop ? paddingInsideDialog.top : 0,
                        aLeft ? paddingInsideDialog.left : 0, aBottom ? paddingInsideDialog.bottom : 0,
                        aRight ? paddingInsideDialog.right : 0));
    }

    private static JPanel wrapWithBorder(JComponent aPanel, Border aBorder) {
        JPanel wrapper = new JPanel(new BorderLayout());
        wrapper.add(aPanel, BorderLayout.CENTER);
        wrapper.setBorder(aBorder);
        return wrapper;
    }
}

Related

  1. addPadding(JComponent comp, int topbottom, int leftright)
  2. pad(JComponent component, int w, int h)
  3. paint(JComponent jc, int padding)
  4. setComponentHeight(JComponent setme, JComponent getme, int padding)
  5. setLeftPadding(JComponent component, int padding)