• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Constraints类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:26,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:26,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:26,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:26,代码来源:SpringLayoutTest.java


示例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()));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:37,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:36,代码来源:SpringLayoutTest.java


示例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());
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:33,代码来源:SpringLayoutTest.java


示例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());

}
 
开发者ID:shannah,项目名称:cn1,代码行数:37,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:36,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:36,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:35,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:13,代码来源:SpringLayoutTest.java


示例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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:46,代码来源:SpringLayoutTest.java



注:本文中的javax.swing.SpringLayout.Constraints类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DataContext类代码示例发布时间:2022-05-22
下一篇:
Java DocPretty类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap