日期:2014-05-20  浏览次数:20881 次

请教贴,JAVA用Swing做的JFrame和JPanel怎样才能一同缩放?
RT
就是比如1个JFrame上面放了个JPanel,怎样按放大或者缩小一同按比例放大和缩小?
详细点,最好有个简单的例子给我看下...

------解决方案--------------------
使用布局管理器就可以,布局管理器有FlowLayout, GridLayout, CardLayout, BoxLayout, BorderLayout等。。。
import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;


public class Test extends JFrame {

private JButton left = new JButton("left");
private JButton right = new JButton("left");
private JButton top = new JButton("left");
private JButton bottom = new JButton("left");
private JButton center = new JButton("left");

public Test() {
this.setTitle("test"); // 标题
this.setBounds(400, 300, 400, 300);
this.setLayout(new BorderLayout()); // 设置布局
this.setDefaultCloseOperation(3); // 关闭退出
this.add(left, BorderLayout.WEST); // 添加左边的按钮
this.add(right, BorderLayout.EAST); // 添加右边的按钮
this.add(top, BorderLayout.NORTH); // 添加上边的按钮
this.add(bottom, BorderLayout.SOUTH); // 添加下边的按钮
this.add(center, BorderLayout.CENTER); // 添加中间的按钮
this.setVisible(true);
}

public static void main(String[] args) {
new Test();
}

}