我创建了一个显示按钮和标签网格的java程序,我想知道如何在标签和按钮上设置约束,以便在拖出窗口时它们不会重新调整大小..有人可以帮忙吗?
这是我的网格布局类
package JFrameTester;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class layout extends JFrame {
JButton button1,button2,button3;
JLabel label1,Label2,Label3;
public layout (){
setLayout(new GridLayout(2, 2));
button1 = new JButton ("button1");
add(button1);
label1 = new JLabel ("label1");
add(label1);
button2 = new JButton ("button1");
add(button2);
Label2 = new JLabel ("Label2");
add(Label2);
button3 = new JButton ("button1");
add(button3);
Label3 = new JLabel ("Label3");
add(Label3);
}
}
这是我的主要课程
public class JFrameTester {
/**
* @param args
*/
public static void main(String[] args) {
layout Lay = new layout();
Lay.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Lay.setVisible(true);
// JFrame frame = new JFrame("BUY COMPUTER");
Lay.setSize(800, 600);
//frame.pack();
// frame.setVisible(true);
Lay.addWindowListener(new MyWindowListener());
}
}