int top = (p.getComponentCount()+1 >= 3) ? 0 : 5;
int left = ((p.getComponentCount()+1) % 2) == 0 ? 0 : 5;
EmptyBorder eb = new EmptyBorder(top,left,5,5);
SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.RAISED);
setBorder(new CompoundBorder(eb, sbb));