62,620
社区成员
发帖
与我相关
我的任务
分享
import javax.swing.*;
//帮你写个例子,时间紧写的一般 呵呵
public class SpringTest extends JFrame{
/**
* @param args
*/
private JPanel jp = new JPanel();
private JLabel jl = new JLabel("会变大哦!");
private JTextField jtf= new JTextField();
private SpringLayout sl = new SpringLayout();//弹簧布局管理器
private SpringTest(){
jp.setLayout(sl);//JPanel设置布局管理器
jp.add(jtf);
jp.add(jl);
//设置各个方向的弹性
sl.putConstraint(SpringLayout.NORTH, jtf, 20,SpringLayout.NORTH, jp);
sl.putConstraint(SpringLayout.NORTH, jl, 20, SpringLayout.NORTH, jp);
sl.putConstraint(SpringLayout.WEST, jtf, 60, SpringLayout.WEST, jp);
sl.putConstraint(SpringLayout.EAST, jp, 10, SpringLayout.EAST, jtf);
Spring jtfw = Spring.constant(0, 100, 400);
sl.putConstraint(SpringLayout.EAST, jtf, jtfw, SpringLayout.WEST, jtf);
sl.putConstraint(SpringLayout.WEST, jl, 10, SpringLayout.WEST, jp);
sl.putConstraint(SpringLayout.EAST, jl, 140, SpringLayout.WEST, jl);
this.add(jp);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("弹簧布局Test");
this.setBounds(100,100,400,100);
this.setVisible(true);
}
public static void main(String[] args) {
new SpringTest();
}
}
import javax.swing.SpringLayout //就是这个布局管理器可以看看