Example usage for javax.swing Spring scale

List of usage examples for javax.swing Spring scale

Introduction

In this page you can find the example usage for javax.swing Spring scale.

Prototype

public static Spring scale(Spring s, float factor) 

Source Link

Document

Returns a spring whose minimum, preferred, maximum and value properties are each multiples of the properties of the argument spring, s.

Usage

From source file:Main.java

public static void main(String[] args) {
    SpringLayout layout = new SpringLayout();
    JPanel p = new JPanel(layout);
    p.setBorder(BorderFactory.createLineBorder(Color.GREEN, 10));

    JLabel l1 = new JLabel("label: width=90%", SwingConstants.CENTER);
    l1.setBorder(BorderFactory.createLineBorder(Color.RED, 1));
    JButton l2 = new JButton("button: width=50%");

    Spring panelw = layout.getConstraint(WIDTH, p);

    SpringLayout.Constraints c1 = layout.getConstraints(l1);
    c1.setX(Spring.constant(0));/*from ww  w. j av  a2s. c  o  m*/
    c1.setY(Spring.constant(20));
    c1.setWidth(Spring.scale(panelw, 0.9f));
    p.add(l1);

    SpringLayout.Constraints c2 = layout.getConstraints(l2);
    c2.setWidth(Spring.scale(panelw, 0.5f));
    layout.putConstraint(SOUTH, l2, -20, SOUTH, p);
    layout.putConstraint(EAST, l2, -20, EAST, p);
    p.add(l2);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(p);
    f.setSize(320, 240);
    f.setVisible(true);
}