Name: pa48320 Date: 08/05/2002 FULL PRODUCT VERSION : java version "1.4.0_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03) Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode) and java version "1.4.1-beta" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14) Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode) FULL OPERATING SYSTEM VERSION : Microsoft Windows XP [Version 5.1.2600] ADDITIONAL OPERATING SYSTEMS : Red Hat Linux release 7.3 (Valhalla) #1 SMP Thu Apr 18 07:17:10 EDT 2002 2.4.18-3bigmem A DESCRIPTION OF THE PROBLEM : SpringLayout fails to properly evaluate constraints under many conditions, one of them being that the order in which constraints are attached is significant. The attached reproduction is a trivial example with a known workaround. However, for many of the non-trivial layouts we have tried to use in a production system there are no known workarounds. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Run this attached source code. 2. Swap constraints A and B and run it again. 3. Note the different behavior. EXPECTED VERSUS ACTUAL BEHAVIOR : In step 1, the text field collapses to width 0 and tracks the East edge of the parent. It should conform to both constraints and resize appropriately, as it does in step 3. In the general case, any legal set of constraints should be obeyed, but they are not. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- package test; import javax.swing.*; public class TestSpring extends JPanel { public TestSpring() { SpringLayout m_layout = new SpringLayout(); setLayout(m_layout); Spring margin = Spring.constant(5); JLabel m_lName = new JLabel("Label"); add(m_lName); SpringLayout.Constraints cons = m_layout.getConstraints(m_lName); cons.setX(margin); cons.setY(margin); cons.setWidth(Spring.constant(60)); JTextField m_tName = new JTextField(); add(m_tName); cons = m_layout.getConstraints(m_tName); cons.setY(margin); // Constraint A m_layout.putConstraint(SpringLayout.WEST, m_tName, 5, SpringLayout.EAST, m_lName); // Constraint B m_layout.putConstraint(SpringLayout.EAST, m_tName, -5, SpringLayout.EAST, this); m_layout.layoutContainer(this); } public static void main(String[] args) { JFrame jf = new JFrame("Test SpringLayout"); jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE); jf.getContentPane().add(new TestSpring()); jf.setLocation(100,100); jf.setSize(400,280); jf.doLayout(); // Just for good measure...1 jf.setVisible(true); } } ---------- END SOURCE ---------- CUSTOMER WORKAROUND : In the general case, none. For the specific case in the source code, swap constraints A and B. (Review ID: 160271) ======================================================================
|