本文整理汇总了Java中javax.swing.SpringLayout.Constraints类的典型用法代码示例。如果您正苦于以下问题:Java Constraints类的具体用法?Java Constraints怎么用?Java Constraints使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Constraints类属于javax.swing.SpringLayout包,在下文中一共展示了Constraints类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddLayoutComponent
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testAddLayoutComponent() throws Exception {
Constraints constraints = new Constraints(Spring.constant(1), Spring.constant(2),
Spring.constant(3), Spring.constant(4));
layout.addLayoutComponent(null, constraints);
Constraints componentCnstraints = layout.getConstraints(null);
assertNotNull(componentCnstraints);
assertSame(componentCnstraints, constraints);
layout.addLayoutComponent(button, null);
componentCnstraints = layout.getConstraints(button);
assertNotNull(componentCnstraints);
assertEquals(componentCnstraints.getX().getValue(), 0);
assertEquals(componentCnstraints.getY().getValue(), 0);
assertEquals(componentCnstraints.getWidth().getValue(), button.getPreferredSize().width);
assertEquals(componentCnstraints.getHeight().getValue(), button.getPreferredSize().height);
layout.addLayoutComponent(button, constraints);
componentCnstraints = layout.getConstraints(button);
assertSame(componentCnstraints, constraints);
}
示例2: testConstraints_SetHeight
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testConstraints_SetHeight() throws Exception {
layout.getConstraints(container).setHeight(Spring.constant(5));
layout.getConstraints(button).setHeight(Spring.constant(6));
layout.getConstraints(button).setHeight(Spring.constant(8));
Constraints constraints = layout.getConstraints(textField);
constraints.setHeight(Spring.constant(8));
constraints.setY(Spring.constant(10));
constraints.setConstraint(SpringLayout.EAST, Spring.constant(40));
layout.getConstraints(panel).setHeight(Spring.constant(6));
constraints.setY(Spring.constant(20));
layout.getConstraints(innerButton).setHeight(Spring.constant(15));
container.setSize(200, 300);
layout.layoutContainer(container);
assertEquals(300, container.getHeight());
assertEquals(8, button.getHeight());
assertEquals(8, textField.getHeight());
assertEquals(6, panel.getHeight());
assertEquals(0, innerButton.getHeight());
}
示例3: testConstraints_SetWidth
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testConstraints_SetWidth() throws Exception {
layout.getConstraints(container).setWidth(Spring.constant(5));
layout.getConstraints(button).setWidth(Spring.constant(6));
layout.getConstraints(button).setWidth(Spring.constant(8));
Constraints constraints = layout.getConstraints(textField);
constraints.setWidth(Spring.constant(8));
constraints.setX(Spring.constant(10));
constraints.setConstraint(SpringLayout.EAST, Spring.constant(40));
layout.getConstraints(panel).setWidth(Spring.constant(6));
constraints.setX(Spring.constant(20));
layout.getConstraints(innerButton).setWidth(Spring.constant(15));
container.setSize(200, 300);
layout.layoutContainer(container);
assertEquals(200, container.getWidth());
assertEquals(8, button.getWidth());
assertEquals(20, textField.getWidth());
assertEquals(6, panel.getWidth());
assertEquals(0, innerButton.getWidth());
}
示例4: testConstraints_SetX
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testConstraints_SetX() throws Exception {
layout.getConstraints(container).setX(Spring.constant(5));
layout.getConstraints(button).setX(Spring.constant(6));
layout.getConstraints(button).setX(Spring.constant(7));
Constraints constraints = layout.getConstraints(textField);
constraints.setX(Spring.constant(8));
constraints.setWidth(Spring.constant(10));
constraints.setConstraint(SpringLayout.EAST, Spring.constant(30));
layout.getConstraints(panel).setX(Spring.constant(7));
constraints.setWidth(Spring.constant(20));
layout.getConstraints(innerButton).setX(Spring.constant(17));
container.setSize(200, 300);
layout.layoutContainer(container);
assertEquals(0, container.getX());
assertEquals(7, button.getX());
assertEquals(10, textField.getX());
assertEquals(7, panel.getX());
assertEquals(0, innerButton.getX());
}
示例5: testConstraints_SetY
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testConstraints_SetY() throws Exception {
layout.getConstraints(container).setY(Spring.constant(5));
layout.getConstraints(button).setY(Spring.constant(6));
layout.getConstraints(button).setY(Spring.constant(8));
Constraints constraints = layout.getConstraints(textField);
constraints.setY(Spring.constant(8));
constraints.setHeight(Spring.constant(10));
constraints.setConstraint(SpringLayout.SOUTH, Spring.constant(40));
layout.getConstraints(panel).setY(Spring.constant(6));
constraints.setHeight(Spring.constant(20));
layout.getConstraints(innerButton).setY(Spring.constant(15));
container.setSize(200, 300);
layout.layoutContainer(container);
assertEquals(0, container.getY());
assertEquals(8, button.getY());
assertEquals(20, textField.getY());
assertEquals(6, panel.getY());
assertEquals(0, innerButton.getY());
}
示例6: testGetConstraints
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testGetConstraints() {
Constraints constraints = layout.getConstraints(null);
assertNotNull(constraints);
layout.addLayoutComponent(component, "not_constraints");
constraints = layout.getConstraints(component);
assertNotNull(constraints);
SpringTest.assertSizes(0, 0, 0, constraints.getX());
SpringTest.assertSizes(0, 0, 0, constraints.getY());
SpringTest.assertSizes(component.getMinimumSize().width,
component.getPreferredSize().width, component.getMaximumSize().width,
constraints.getWidth());
SpringTest.assertSizes(component.getMinimumSize().height,
component.getPreferredSize().height, component.getMaximumSize().height,
constraints.getHeight());
layout.addLayoutComponent(component, null);
constraints = layout.getConstraints(component);
assertNotNull(constraints);
SpringTest.assertSizes(0, 0, 0, constraints.getX());
SpringTest.assertSizes(0, 0, 0, constraints.getY());
SpringTest.assertSizes(component.getMinimumSize().width,
component.getPreferredSize().width, component.getMaximumSize().width,
constraints.getWidth());
SpringTest.assertSizes(component.getMinimumSize().height,
component.getPreferredSize().height, component.getMaximumSize().height,
constraints.getHeight());
Constraints componentConstraints = new SpringLayout.Constraints(component);
layout.addLayoutComponent(component, constraints);
constraints = layout.getConstraints(component);
assertFalse(componentConstraints.equals(constraints));
SpringTest.assertValues(componentConstraints.getX(), constraints.getX());
SpringTest.assertValues(componentConstraints.getY(), constraints.getY());
SpringTest.assertValues(componentConstraints.getWidth(), constraints.getWidth());
SpringTest.assertValues(componentConstraints.getHeight(), constraints.getHeight());
assertNotNull(layout.getConstraints(new JLabel()));
}
示例7: testRemoveLayoutComponent
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testRemoveLayoutComponent() {
layout.removeLayoutComponent(null);
layout.removeLayoutComponent(new JLabel());
layout.addLayoutComponent(component, new SpringLayout.Constraints(component));
layout.removeLayoutComponent(null);
layout.removeLayoutComponent(new JLabel());
JPanel panel = new JPanel(layout);
panel.add(component);
Constraints constraints1 = layout.getConstraints(component);
layout.removeLayoutComponent(component);
Constraints constraints2 = layout.getConstraints(component);
assertNotSame(constraints1, constraints2);
SpringTest.assertSizes(0, 0, 0, 0, constraints2.getX());
SpringTest.assertSizes(0, 0, 0, 0, constraints2.getY());
component = new JTextField();
JLabel label = new JLabel("label");
setComponentSizes(label, Spring.constant(5), Spring.constant(10));
panel.add(component);
panel.add(label);
layout.getConstraints(label).setX(Spring.constant(15));
layout.putConstraint(SpringLayout.WEST, component,
5,
SpringLayout.EAST, label);
layout.layoutContainer(panel);
assertEquals(15, label.getX());
layout.removeLayoutComponent(label);
layout.layoutContainer(panel);
assertEquals(0, label.getX());
}
示例8: testInvalidateLayout
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testInvalidateLayout() throws Exception {
JFrame frame = new JFrame("testMinimumLayoutSize");
frame.setContentPane(container);
layout = new SpringLayout();
container.setLayout(layout);
Constraints buttonConstraints = layout.getConstraints(button);
buttonConstraints.setHeight(Spring.constant(33, 34, 35));
Constraints containerConstraints = layout.getConstraints(container);
containerConstraints.setConstraint(SpringLayout.SOUTH,
buttonConstraints.getConstraint(SpringLayout.SOUTH));
containerConstraints.setConstraint(SpringLayout.EAST,
buttonConstraints.getConstraint(SpringLayout.EAST));
containerConstraints.setConstraint(SpringLayout.WEST, Spring.constant(3));
frame.pack();
frame.setVisible(true);
frame.setSize(100, 200);
Spring width = buttonConstraints.getWidth();
if (isHarmony()) {
assertEquals(5, width.getValue());
} else {
assertEquals(115, width.getValue());
}
frame.setSize(200, 300);
layout.invalidateLayout(container);
assertSame(width, buttonConstraints.getWidth());
if (isHarmony()) {
assertEquals(5, width.getValue());
} else {
assertEquals(115, width.getValue());
}
}
示例9: testConstraints_GetHeight
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testConstraints_GetHeight() throws Exception {
layout.getConstraints(container).setHeight(Spring.constant(5));
layout.getConstraints(button).setHeight(Spring.constant(6));
layout.getConstraints(button).setHeight(Spring.constant(8));
Constraints constraints = layout.getConstraints(textField);
constraints.setHeight(Spring.constant(8));
constraints.setY(Spring.constant(10));
constraints.setConstraint(SpringLayout.EAST, Spring.constant(40));
layout.getConstraints(panel).setHeight(Spring.constant(6));
constraints.setY(Spring.constant(20));
layout.getConstraints(innerButton).setHeight(Spring.constant(15));
container.setSize(200, 300);
layout.layoutContainer(container);
SpringTest.assertSizes(5, 5, 5,
layout.getConstraints(container).getHeight());
SpringTest.assertSizes(8, 8, 8,
layout.getConstraints(button).getHeight());
SpringTest.assertSizes(8, 8, 8,
layout.getConstraints(textField).getHeight());
SpringTest.assertSizes(6, 6, 6,
layout.getConstraints(panel).getHeight());
SpringTest.assertSizes(15, 15, 15,
layout.getConstraints(innerButton).getHeight());
container.setSize(200, 300);
layout.layoutContainer(button);
SpringTest.assertSizes(8, 8, 8,
layout.getConstraints(button).getHeight());
}
示例10: testConstraints_GetWidth
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testConstraints_GetWidth() throws Exception {
layout.getConstraints(container).setWidth(Spring.constant(5));
layout.getConstraints(button).setWidth(Spring.constant(6));
layout.getConstraints(button).setWidth(Spring.constant(8));
Constraints constraints = layout.getConstraints(textField);
constraints.setWidth(Spring.constant(8));
constraints.setX(Spring.constant(10));
constraints.setConstraint(SpringLayout.EAST, Spring.constant(40));
layout.getConstraints(panel).setWidth(Spring.constant(6));
constraints.setX(Spring.constant(20));
layout.getConstraints(innerButton).setWidth(Spring.constant(15));
container.setSize(200, 300);
layout.layoutContainer(container);
SpringTest.assertSizes(5, 5, 5,
layout.getConstraints(container).getWidth());
SpringTest.assertSizes(8, 8, 8,
layout.getConstraints(button).getWidth());
SpringTest.assertSizes(20, 20, 20,
layout.getConstraints(textField).getWidth());
SpringTest.assertSizes(6, 6, 6,
layout.getConstraints(panel).getWidth());
SpringTest.assertSizes(15, 15, 15,
layout.getConstraints(innerButton).getWidth());
container.setSize(200, 300);
layout.layoutContainer(button);
SpringTest.assertSizes(8, 8, 8,
layout.getConstraints(button).getWidth());
}
示例11: testConstraints_GetX
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testConstraints_GetX() throws Exception {
layout.getConstraints(container).setX(Spring.constant(5));
layout.getConstraints(button).setX(Spring.constant(6));
layout.getConstraints(button).setX(Spring.constant(7));
Constraints constraints = layout.getConstraints(textField);
constraints.setX(Spring.constant(8));
constraints.setWidth(Spring.constant(10));
constraints.setConstraint(SpringLayout.EAST, Spring.constant(30));
layout.getConstraints(panel).setX(Spring.constant(7));
constraints.setWidth(Spring.constant(20));
layout.getConstraints(innerButton).setX(Spring.constant(17));
container.setSize(200, 300);
layout.layoutContainer(container);
SpringTest.assertSizes(0, 0, 0,
layout.getConstraints(container).getX());
SpringTest.assertSizes(7, 7, 7,
layout.getConstraints(button).getX());
SpringTest.assertSizes(10, 10, 10,
layout.getConstraints(textField).getX());
SpringTest.assertSizes(7, 7, 7,
layout.getConstraints(panel).getX());
SpringTest.assertSizes(17, 17, 17,
layout.getConstraints(innerButton).getX());
container.setSize(200, 300);
layout.layoutContainer(button);
SpringTest.assertSizes(0, 0, 0,
layout.getConstraints(button).getX());
}
示例12: testConstraints_GetY
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testConstraints_GetY() throws Exception {
layout.getConstraints(container).setY(Spring.constant(5));
layout.getConstraints(button).setY(Spring.constant(6));
layout.getConstraints(button).setY(Spring.constant(8));
Constraints constraints = layout.getConstraints(textField);
constraints.setY(Spring.constant(8));
constraints.setHeight(Spring.constant(10));
constraints.setConstraint(SpringLayout.SOUTH, Spring.constant(40));
layout.getConstraints(panel).setY(Spring.constant(6));
constraints.setHeight(Spring.constant(20));
layout.getConstraints(innerButton).setY(Spring.constant(15));
container.setSize(200, 300);
layout.layoutContainer(container);
SpringTest.assertSizes(0, 0, 0,
layout.getConstraints(container).getY());
SpringTest.assertSizes(8, 8, 8,
layout.getConstraints(button).getY());
SpringTest.assertSizes(20, 20, 20,
layout.getConstraints(textField).getY());
SpringTest.assertSizes(6, 6, 6,
layout.getConstraints(panel).getY());
SpringTest.assertSizes(15, 15, 15,
layout.getConstraints(innerButton).getY());
container.setSize(200, 300);
layout.layoutContainer(button);
SpringTest.assertSizes(0, 0, 0, layout.getConstraints(button).getY());
}
示例13: assertEdges
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
private void assertEdges(final Constraints constraints,
final int west, final int east,
final int north, final int south) {
assertEquals(west,
constraints.getConstraint(SpringLayout.WEST).getValue());
assertEquals(east,
constraints.getConstraint(SpringLayout.EAST).getValue());
assertEquals(north,
constraints.getConstraint(SpringLayout.NORTH).getValue());
assertEquals(south,
constraints.getConstraint(SpringLayout.SOUTH).getValue());
}
示例14: testSpringLayout
import javax.swing.SpringLayout.Constraints; //导入依赖的package包/类
public void testSpringLayout() {
SpringLayout.Constraints constrains = new SpringLayout.Constraints();
assertNull(constrains.getX());
assertNull(constrains.getY());
assertNull(constrains.getWidth());
assertNull(constrains.getHeight());
constrains = new SpringLayout.Constraints(Spring.width(component), Spring.constant(0));
assertNull(constrains.getWidth());
assertNull(constrains.getHeight());
SpringTest.assertSizes(0, 0, 0, 0, constrains.getY());
SpringTest.assertSizes(component.getMinimumSize().width,
component.getPreferredSize().width, component.getMaximumSize().width,
constrains.getX());
assertNull(constrains.getWidth());
assertNull(constrains.getHeight());
constrains = new SpringLayout.Constraints(component);
SpringTest.assertSizes(0, 0, 0, 0, constrains.getX());
SpringTest.assertSizes(0, 0, 0, 0, constrains.getY());
SpringTest.assertSizes(component.getMinimumSize().width,
component.getPreferredSize().width, component.getMaximumSize().width,
constrains.getWidth());
SpringTest.assertSizes(component.getMinimumSize().height,
component.getPreferredSize().height, component.getMaximumSize().height,
constrains.getHeight());
constrains = new SpringLayout.Constraints(Spring.constant(1), Spring.constant(2),
Spring.constant(3), Spring.constant(4));
SpringTest.assertSizes(1, 1, 1, 1, constrains.getX());
SpringTest.assertSizes(2, 2, 2, 2, constrains.getY());
SpringTest.assertSizes(3, 3, 3, 3, constrains.getWidth());
SpringTest.assertSizes(4, 4, 4, 4, constrains.getHeight());
constrains = new SpringLayout.Constraints(Spring.constant(1), null);
SpringTest.assertSizes(1, 1, 1, 1, constrains.getX());
Container container = new JPanel();
container.setLayout(layout);
container.add(new JLabel(""));
constrains = layout.getConstraints(component);
SpringTest.assertSizes(0, 0, 0, 0, constrains.getX());
SpringTest.assertSizes(0, 0, 0, 0, constrains.getY());
SpringTest.assertSizes(component.getMinimumSize().width,
component.getPreferredSize().width, component.getMaximumSize().width,
constrains.getWidth());
SpringTest.assertSizes(component.getMinimumSize().height,
component.getPreferredSize().height, component.getMaximumSize().height,
constrains.getHeight());
}