首页 > 代码库 > Java swing 之边界布局
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(); } }
Java swing 之边界布局
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。