Java swing 之边界布局

2020-11-27 00:40

阅读:824

标签:java   swing   

/**
 *  java 边界布局
 *  @author gao
 */
package com.gao;

import java.awt.BorderLayout;

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

public class BorderLayoutDemo extends JFrame{
   private JPanel contentPane;
   private JButton westButton;
   private JButton southButton;
   private JButton eastButton;
   private JButton northButton;
   private JButton centreButton;
	public BorderLayoutDemo(){
		this.contentPane=new JPanel();
		this.contentPane.setBorder(new EmptyBorder(5,5,5,5));
		this.contentPane.setLayout(new BorderLayout(0,0));
		this.setContentPane(contentPane);
		this.westButton=new JButton("西部");
		this.southButton=new JButton("南部");
		this.eastButton=new JButton("东部");
		this.northButton=new JButton("北部");
		this.centreButton=new JButton("中部");
		this.contentPane.add(westButton,BorderLayout.WEST);
		this.contentPane.add(southButton,BorderLayout.SOUTH);
		this.contentPane.add(northButton,BorderLayout.NORTH);
		this.contentPane.add(eastButton,BorderLayout.EAST);
		this.contentPane.add(centreButton,BorderLayout.CENTER);
		
    	this.setTitle("边界布局");
    	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	this.setBounds(100, 100, 450, 300);
    	this.setVisible(true);
    }
	public static void main(String[]args){
    	 BorderLayoutDemo example=new BorderLayoutDemo();
     }
}
mamicode.com,搜素材

Java swing 之边界布局

标签:java   swing   

原文地址:http://blog.csdn.net/guanjungao/article/details/24845015


评论


亲,登录后才可以留言!