The VERTICAL_CENTER
constraint type was introduced by Java 6 which is why it doesn't work for you in Java 5. But the invariants specify that
VERTICAL_CENTER = NORTH + HEIGHT/2
SOUTH = NORTH + HEIGHT
Substituting and re-arranging these equations we get
NORTH = SOUTH - HEIGHT
VERTICAL_CENTER = SOUTH - HEIGHT/2
VERTICAL_CENTER + HEIGHT/2 = SOUTH
HEIGHT/2 = SOUTH - VERTICAL_CENTER
HEIGHT = 2*(SOUTH - VERTICAL_CENTER)
So if you are currently setting SOUTH
and VERTICAL_CENTER
then you can achieve the same effect by setting the height to a spring of size 2*(SOUTH - VERTICAL_CENTER)
. So replace
constr.putConstraint(SpringLayout.SOUTH, southSpring);
constr.putConstraint(SpringLayout.VERTICAL_CENTER, vcSpring);
with
constr.putConstraint(SpringLayout.SOUTH, southSpring);
constr.setHeight(
Spring.scale(Spring.sum(southSpring, Spring.minus(vcSpring)),
2.0f));