List of usage examples for java.awt BorderLayout getConstraints
public Object getConstraints(Component comp)
From source file:Main.java
public Main() { JButton btn1 = new JButton("Button1"); JButton btn2 = new JButton("Button2"); JButton btn3 = new JButton("Button3"); JButton btn4 = new JButton("Button4"); JButton btn5 = new JButton("Button5"); JButton btn6 = new JButton("Button6"); BorderLayout borderLayout = new BorderLayout(20, 30); setLayout(borderLayout);/*from w w w . j av a 2 s . c om*/ add("North", btn1); add("West", btn2); add("Center", btn3); add("Center", btn4); add("South", btn5); add("East", btn6); System.out.println(borderLayout.getConstraints(btn1)); }
From source file:org.eclipse.wb.tests.designer.core.model.association.InvocationSecondaryAssociationTest.java
public void test_0() throws Exception { setFileContentSrc("test/AFrame.java", getTestSource("public class AFrame extends JFrame {", " protected void addGB(Container parent, Component child, String constraints) {", " parent.add(child, constraints);", " }", "}")); setFileContentSrc("test/AFrame.wbp-component.xml", getSourceDQ("<?xml version='1.0' encoding='UTF-8'?>", "<component xmlns='http://www.eclipse.org/wb/WBPComponent'>", " <methods>", " <method name='addGB'>", " <parameter type='java.awt.Container' parent2='true'/>", " <parameter type='java.awt.Component' child2='true'/>", " <parameter type='java.lang.String'/>", " </method>", " </methods>", "</component>")); waitForAutoBuild();//from w w w . j a v a2 s . c om // ContainerInfo frame = parseContainer("public class Test extends AFrame {", " public Test() {", " addGB(getContentPane(), new JButton('north'), BorderLayout.NORTH);", " addGB(getContentPane(), new JButton('west'), BorderLayout.WEST);", " }", "}"); frame.refresh(); // prepare contentPane with BorderLayout assertEquals(1, frame.getChildrenComponents().size()); ContainerInfo contentPane = (ContainerInfo) frame.getChildrenComponents().get(0); BorderLayout borderLayout = (BorderLayout) contentPane.getContainer().getLayout(); // check children of contentPane assertEquals(2, contentPane.getChildrenComponents().size()); { Container container = contentPane.getContainer(); Component[] components = container.getComponents(); assertEquals(2, components.length); } // check "button north" { ComponentInfo button = contentPane.getChildrenComponents().get(0); assertSame(BorderLayout.NORTH, borderLayout.getConstraints(button.getComponent())); } // check "button west" { ComponentInfo button = contentPane.getChildrenComponents().get(1); assertSame(BorderLayout.WEST, borderLayout.getConstraints(button.getComponent())); } // check association for "button" { ComponentInfo button = contentPane.getChildrenComponents().get(0); InvocationSecondaryAssociation association = (InvocationSecondaryAssociation) button.getAssociation(); assertEquals("addGB(getContentPane(), new JButton(\"north\"), BorderLayout.NORTH)", association.getSource()); assertEquals("addGB(getContentPane(), new JButton(\"north\"), BorderLayout.NORTH);", m_lastEditor.getSource(association.getStatement())); // can not be moved try { association.move(null); fail(); } catch (NotImplementedException e) { } // can not be reparented try { association.setParent(null); fail(); } catch (NotImplementedException e) { } } }