Java Utililty Methods JComponent Padding

List of utility methods to do JComponent Padding

Description

The list of methods to do JComponent Padding are organized into topic(s).

Method

voidaddPadding(JComponent comp, int topbottom, int 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.
addPadding(comp, topbottom, leftright, topbottom, leftright);
JPanelmakePaddedPanel(JComponent aComponent, Insets aInsets)
make Padded Panel
return wrapWithBorder(aComponent,
        BorderFactory.createEmptyBorder(aInsets.top, aInsets.left, aInsets.bottom, aInsets.right));
voidpad(JComponent component, int w, int h)
pad
Dimension size = component.getPreferredSize();
size.width += w;
size.height += h;
component.setPreferredSize(size);
BufferedImagepaint(JComponent jc, int padding)
Paint a JComponent as a BufferedImage
Dimension d = jc.getSize();
BufferedImage bi = new BufferedImage(d.width + 2 * padding, d.height + 2 * padding,
        BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
g.translate(padding, padding);
jc.paint(g);
...
voidsetComponentHeight(JComponent setme, JComponent getme, int padding)
set Component Height
setme.setPreferredSize(
        new Dimension(getme.getPreferredSize().width, getme.getPreferredSize().height + padding));
voidsetLeftPadding(JComponent component, int padding)
set Left Padding
component.setBorder(
        BorderFactory.createEmptyBorder(DEFAULT_PADDING, padding, DEFAULT_PADDING, DEFAULT_PADDING));