BorderLayout布局测试

import java.awt.BorderLayout;

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

public class TestAwt {
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setTitle("BorderLayout 测试");
		frame.setSize(500,500);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLocationRelativeTo(null);
		{
			BorderLayout bl = new BorderLayout();
			JPanel jPanel = new JPanel(bl);
			jPanel.add(new JButton("TestButton"),BorderLayout.NORTH);
			jPanel.add(new JButton("TestButton"),BorderLayout.EAST);
			jPanel.add(new JButton("TestButton"),BorderLayout.SOUTH);
			jPanel.add(new JButton("TestButton"),BorderLayout.WEST);
			jPanel.add(new JButton("TestButton"),BorderLayout.CENTER);
			frame.add(jPanel);
		}
		frame.setVisible(true);
	}
}

 

 

你可能感兴趣的:(BorderLayout)