Java Utililty Methods Swing Border

List of utility methods to do Swing Border

Description

The list of methods to do Swing Border are organized into topic(s).

Method

BordercreateRightBorder(int size, Color color)
create Right Border
if (color != null) {
    return BorderFactory.createMatteBorder(size, 0, size, size, color);
return BorderFactory.createEmptyBorder(size, 0, size, size);
BordercreateRoundedEmptyBorder(final int top, final int left, final int bottom, final int right, final int arc, final Color color)
create Rounded Empty Border
if (top < 0 | left < 0 | bottom < 0 | right < 0 | arc < 0) {
    throw new IllegalArgumentException();
final int dr = (int) Math.ceil((1 - 1 / Math.sqrt(2)) * arc);
return new Border() {
    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        if (c.isOpaque()) {
...
BordercreateTitledBorder(Color color, String name)
create Titled Border
return BorderFactory.createTitledBorder(BorderFactory.createLineBorder(color), name);
JPanelcreateVerticalBox(Border border, Component... comps)
create Vertical Box
JPanel res = createVerticalBox(comps);
res.setBorder(border);
return res;
voiddrawBorderTrans(Graphics2D g, JComponent focusOwner, JComponent area)
draw Border Trans
if (focusOwner != null && focusOwner.isFocusOwner()) {
    g.setColor(new Color(180, 180, 180));
    g.drawRect(0, 0, area.getWidth() - 1, area.getHeight() - 1);
voiddrawBorderWhite(Graphics2D g, JComponent focusOwner, JComponent area)
draw Border White
g.setColor(new Color(255, 255, 255));
g.drawRect(0, 0, area.getWidth() - 1, area.getHeight() - 1);
g.drawRect(1, 1, area.getWidth() - 3, area.getHeight() - 3);
if (focusOwner != null && focusOwner.isFocusOwner()) {
    g.setColor(new Color(240, 240, 240));
    g.drawRect(0, 0, area.getWidth() - 1, area.getHeight() - 1);
    g.drawRect(1, 1, area.getWidth() - 3, area.getHeight() - 3);
voiddrawDisabledBorder(Graphics g, int x, int y, int w, int h)
draw Disabled Border
g.setColor(MetalLookAndFeel.getControlShadow());
drawRect(g, x, y, w - 1, h - 1);
voiddrawDisabledBorder(Graphics g, int x, int y, int w, int h)
draw Disabled Border
g.translate(x, y);
g.setColor(MetalLookAndFeel.getControlShadow());
g.drawRect(0, 0, w - 1, h - 1);
g.translate(-x, -y);
DimensionextendByBorder(JLabel label, Dimension dm)
extend By Border
if (label == null) {
    throw new IllegalArgumentException("label==null");
if (dm == null) {
    throw new IllegalArgumentException("dm==null");
Border border = label.getBorder();
if (border != null) {
...
ContainerfindComponentWithBorder(JComponent panel, Class aClass)
find Component With Border
for (int n = 0; n < panel.getComponentCount(); n++) {
    if (panel.getComponent(n) instanceof JComponent) {
        JComponent comp = (JComponent) panel.getComponent(n);
        if (comp.getBorder() != null && aClass.isAssignableFrom(comp.getBorder().getClass())) {
            return comp;
        Container con = findComponentWithBorder(comp, aClass);
        if (con != null) {
...