/** * Tests the combination of a default size spec with an upper bound that shall ensure a maximum * size. */ public void testDefaultWithUpperBound() { TestComponent c1 = new TestComponent(10, 10, 50, 50); FormLayout layout = new FormLayout("[default,20px]", "[default,20px]"); JPanel panel = new JPanel(layout); panel.add(c1, cc.xy(1, 1)); Dimension minimumLayoutSize = layout.minimumLayoutSize(panel); Dimension preferredLayoutSize = layout.preferredLayoutSize(panel); assertEquals("Minimum layout width", 10, minimumLayoutSize.width); assertEquals("Minimum layout height", 10, minimumLayoutSize.height); assertEquals("Preferred layout width", 20, preferredLayoutSize.width); assertEquals("Preferred layout height", 20, preferredLayoutSize.height); panel.setSize(minimumLayoutSize); panel.doLayout(); int columnWidth = c1.getWidth(); int rowHeight = c1.getHeight(); assertEquals("Column width (container min)", 10, columnWidth); assertEquals("Row height (container min)", 10, rowHeight); panel.setSize(preferredLayoutSize); panel.doLayout(); columnWidth = c1.getWidth(); rowHeight = c1.getHeight(); assertEquals("Column width (container pref)", 20, columnWidth); assertEquals("Row height (container pref)", 20, rowHeight); }
/** * Checks and verifies that components that span multiple columns and that expand the container * are measured using the correct measure. */ public void testExtraExpansionHonorsCurrentMeasure() { TestComponent c1 = new TestComponent(10, 1, 50, 1); TestComponent c2 = new TestComponent(10, 1, 50, 1); TestComponent c3 = new TestComponent(10, 1, 50, 1); TestComponent c4 = new TestComponent(10, 1, 50, 1); FormLayout layout = new FormLayout("10px, 15px:grow, 20px", "pref, pref"); JPanel panel = new JPanel(layout); panel.add(c1, cc.xy(1, 1)); panel.add(c2, cc.xy(2, 1)); panel.add(c3, cc.xy(3, 1)); panel.add(c4, cc.xyw(1, 2, 2)); int minimumLayoutWidth = layout.minimumLayoutSize(panel).width; int preferredLayoutWidth = layout.preferredLayoutSize(panel).width; assertEquals("Minimum layout width", 45, minimumLayoutWidth); assertEquals("Preferred layout width", 70, preferredLayoutWidth); }