The documentation of SpringLayout says that it´s available since java 1.4, I have like 7 old macs that can´t be upgraded to any newer version of mac os 10.5 which leads me to have only java 1.5.0_30 at most. The problem is that I have an app that works with spring layout and I'm always getting this stack back trace:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.SpringLayout$SpringProxy.getValue(SpringLayout.java:674)
at javax.swing.Spring$CompoundSpring.getValue(Spring.java:420)
at javax.swing.Spring$CompoundSpring.getValue(Spring.java:420)
at javax.swing.SpringLayout.layoutContainer(SpringLayout.java:1004)
at java.awt.Container.layout(Container.java:1401)
at java.awt.Container.doLayout(Container.java:1390)
at java.awt.Container.validateTree(Container.java:1473)
at java.awt.Container.validateTree(Container.java:1480)
at java.awt.Container.validateTree(Container.java:1480)
at java.awt.Container.validateTree(Container.java:1480)
at java.awt.Container.validateTree(Container.java:1480)
at java.awt.Container.validate(Container.java:1448)
at java.awt.Window.show(Window.java:516)
at java.awt.Component.show(Component.java:1317)
at java.awt.Component.setVisible(Component.java:1270)
Is there any solution, any jar or something similar?
Please avoid answers like "Upgrade you computers"
UPDATE: I dicovered that there is SpringLayout on Java, but you cant use VERTICAL_LAYOUT with SOUTH. I don´t know why.
UPDATE 2: Following the instruction of Ian I did the following code and it is still not working on Java 5
springLayout.putConstraint(SpringLayout.NORTH, myImage,
Spring.sum(springLayout.getConstraint(SpringLayout.SOUTH, myPanel) ,
Spring.sum(Spring.scale(Spring.minus(springLayout.getConstraint(SpringLayout.HEIGHT, myImage)),0.5f),
Spring.scale(Spring.minus(springLayout.getConstraint(SpringLayout.HEIGHT, myPanel)),0.5f)
)
), SpringLayout.NORTH, myPanel);
UPDATE 3: Replacing springLayout.getConstraint(SpringLayout.HEIGHT, myImage)
with springLayout.getConstraints(myImage).getHeight()
it worked perfectly fine. :)