本文整理汇总了Java中javax.swing.SpringLayout.Constraints.setWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Constraints.setWidth方法的具体用法?Java Constraints.setWidth怎么用?Java Constraints.setWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.SpringLayout.Constraints
的用法示例。
在下文中一共展示了Constraints.setWidth方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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());
}
示例3: 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());
}
示例4: 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());
}
示例5: testMinimumLayoutSize
import javax.swing.SpringLayout.Constraints; //导入方法依赖的package包/类
public void testMinimumLayoutSize() throws Exception {
//container
setComponentSizes(button, Spring.constant(2, 5, 100), Spring.constant(3, 6, 101));
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));
layout.layoutContainer(container);
assertEquals(2, layout.minimumLayoutSize(container).width);
assertEquals(33, layout.minimumLayoutSize(container).height);
//putConstraints()
assertEquals(button.getInsets().left + button.getInsets().right,
layout.minimumLayoutSize(button).width);
assertEquals(panel.getInsets().left + panel.getInsets().right,
layout.minimumLayoutSize(panel).width);
assertEquals(innerButton.getInsets().left + innerButton.getInsets().right,
layout.minimumLayoutSize(innerButton).width);
buttonConstraints.setX(Spring.constant(20));
assertEquals(button.getInsets().left + button.getInsets().right,
layout.minimumLayoutSize(button).width);
assertEquals(0, layout.getConstraint(SpringLayout.EAST, button).getPreferredValue());
buttonConstraints.setWidth(Spring.constant(100));
assertEquals(100 + button.getInsets().left + button.getInsets().right,
layout.minimumLayoutSize(button).width);
layout.getConstraints(innerButton).setX(Spring.constant(20));
assertEquals(innerButton.getInsets().left + innerButton.getInsets().right,
layout.minimumLayoutSize(innerButton).width);
layout.getConstraints(innerButton).setWidth(Spring.constant(100));
assertEquals(100 + innerButton.getInsets().left + innerButton.getInsets().right,
layout.minimumLayoutSize(innerButton).width);
layout.getConstraints(panel).setX(Spring.constant(20));
assertEquals(panel.getInsets().left + panel.getInsets().right,
layout.minimumLayoutSize(panel).width);
assertEquals(0, layout.getConstraint(SpringLayout.EAST, panel).getPreferredValue());
layout.getConstraints(panel).setWidth(Spring.constant(100));
assertEquals(100 + panel.getInsets().left + panel.getInsets().right,
layout.minimumLayoutSize(panel).width);
assertEquals(100, layout.getConstraint(SpringLayout.EAST, panel).getPreferredValue());
layout = new SpringLayout();
container.setLayout(layout);
layout.putConstraint(SpringLayout.SOUTH, button, Spring.constant(15),
SpringLayout.NORTH, container);
layout.putConstraint(SpringLayout.EAST, button, Spring.constant(5),
SpringLayout.WEST, container);
assertEquals(panel.getInsets().left + panel.getInsets().right,
layout.minimumLayoutSize(panel).width);
assertEquals(innerButton.getInsets().left + innerButton.getInsets().right,
layout.minimumLayoutSize(innerButton).width);
assertEquals(5 + button.getInsets().left + button.getInsets().right,
layout.minimumLayoutSize(button).width);
}
示例6: testConstraints_SetConstraint
import javax.swing.SpringLayout.Constraints; //导入方法依赖的package包/类
public void testConstraints_SetConstraint() throws Exception {
Constraints constraints;
layout.getConstraints(container).setConstraint(SpringLayout.WEST,
Spring.constant(5));
layout.getConstraints(button).setConstraint(SpringLayout.WEST,
Spring.constant(6));
layout.getConstraints(button).setX(Spring.constant(7));
constraints = layout.getConstraints(textField);
constraints.setX(Spring.constant(8));
constraints.setWidth(Spring.constant(10));
constraints.setConstraint(SpringLayout.EAST, Spring.constant(30));
layout.getConstraints(panel).setConstraint(SpringLayout.WEST,
Spring.constant(7));
constraints.setWidth(Spring.constant(20));
layout.getConstraints(panel).setConstraint(SpringLayout.EAST,
Spring.constant(17));
constraints = layout.getConstraints(innerButton);
constraints.setX(Spring.constant(18));
constraints.setWidth(Spring.constant(20));
constraints.setConstraint(SpringLayout.EAST, Spring.constant(50));
container.setSize(200, 300);
layout.layoutContainer(container);
assertEdges(layout.getConstraints(container),
0, 200, 0, 300);
assertEdges(layout.getConstraints(button),
7, 12, 0, 5);
assertEdges(layout.getConstraints(textField),
10, 30, 0, 10);
if (isHarmony()) {
assertEdges(layout.getConstraints(panel),
7, 17, 0, 3);
} else {
assertEdges(layout.getConstraints(panel),
14, 17, 0, 3);
}
assertEdges(layout.getConstraints(innerButton),
30, 50, 0, 10);
component = new JPanel();
setComponentSizes(component, Spring.constant(10), Spring.constant(5));
layout.getConstraints(panel).setConstraint(SpringLayout.NORTH,
Spring.constant(1));
assertEdges(layout.getConstraints(component),
0, 10, 0, 5);
}