<Swing Dev> SpringLayout equivalent behavior

Tadeus Prastowo tadeus.prastowo at yandex.com
Mon Apr 20 11:54:53 UTC 2015


Hi!

It is shown on https://docs.oracle.com/javase/tutorial/uiswing/layout/spring.html#alternatives that

layout.putConstraint(
  SpringLayout.WEST, label,
  5,
  SpringLayout.WEST, contentPane);

is equivalent to

SpringLayout.Constraints  contentPaneCons = layout.getConstraints(contentPane);
contentPaneCons.setX(
  Spring.sum(
    Spring.constant(5),
    contentPaneCons.getConstraint(SpringLayout.WEST)
));

IMO, setting the X of a container from within the container will have no effect because the one who will set the container's X will be the layout manager of its parent container. Therefore, I think the correct one is:

SpringLayout.Constraints  labelCons = layout.getConstraints(label);
labelCons.setX(
  Spring.sum(
    Spring.constant(5),
    labelCons.getConstraint(SpringLayout.WEST)
));

What do you guys think?

Thank you.

--
Best regards,
Eus



More information about the swing-dev mailing list