1,FlowLayout

窗口的默认布局

设置窗口布局方法(下面不重复

setLayout(new FlowLayout());

设置容器布局方法

比如容器 con1

con1.setLayout(new FlowLayout())

2.BorderLayout

        add(new JLabel("huang"),BorderLayout.CENTER);
add(new JLabel("huang"),BorderLayout.NORTH);
add(new JLabel("huang"),BorderLayout.WEST);
//如果有组件con1,con1.add(con2,bor2.CENTER)

3.GridLayout

GridLayout grid1=new GridLayout(a,b);//弄一个aXb的网格

写一个棋盘

        JPanel pane1=new JPanel();
GridLayout grid1=new GridLayout(12,12);
pane1.setLayout(grid1);
Label label[][]=new Label[12][12];
for(int i=0;i<12;i++){
for(int j=0;j<12;j++){
label[i][j]=new Label();
if((i+j)%2==0)
label[i][j].setBackground(Color.black);
else
label[i][j].setBackground(Color.white);
pane1.add(label[i][j]);
}
}
add(pane1,BorderLayout.CENTER);
add(new JButton("north"),BorderLayout.NORTH);
add(new JButton("south"),BorderLayout.SOUTH);
add(new JButton("west"),BorderLayout.WEST);
add(new JButton("east"),BorderLayout.EAST);

5.BoxLayout布局

和上面的布局有点不同,语法上像一个组件一样add上去

//方法一
BoxLayout box1=new BoxLayout(Container con1,1)
//方法二
//使用Box类的静态方法
Box.createHorizontalBox()//水平盒式布局
Box.createVerticalBox()//垂直~
Box.createHorizontalStruct(int width)//空白
Box.createVerticalStruct(int height)//~
        setLayout(new FlowLayout());
Box box1,box2,boxBase;
boxBase=Box.createHorizontalBox();
box1=Box.createVerticalBox();
box1.add(new JLabel("name"));
box1.add(Box.createVerticalStrut(8));
box1.add(new JLabel("sex"));
box1.add(Box.createVerticalStrut(8));
box1.add(new JLabel("age"));
box2=Box.createVerticalBox();
box2.add(new JTextField(10));
box2.add(Box.createVerticalStrut(8));
box2.add(new JTextField(10));
box2.add(Box.createVerticalStrut(8));
box2.add(new JTextField(10));
boxBase.add(box1);
boxBase.add(Box.createHorizontalStrut(8));
boxBase.add(box2);
add(boxBase);

swing常用布局的更多相关文章

  1. 第13章 Swing程序组件----常用布局管理器

    在Swing中,每个组件在容器中都有一个具体的位置和大小,而在容器中摆放各种组件时很难判断其具体位置和大小.布局管理器提供了Swing组件安排.展示在容器中的方法及基本的布局功能. Swing提供的常 ...

  2. python:页面布局 后台管理页面之常用布局

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. 常用布局,div竖直居中

    常用两列布局,多列布局和div竖直居中 body { margin:; padding:; } .w200 { width: 200px; } .mar-left200 { margin-left: ...

  4. 跟我学android-android常用布局介绍

    在上一章我们曾经谈到,Android平台的界面 是使用XML的方式设计的,然后在上一章我们只做了一个简单的界面,在这章,我们将介绍如何使用常用的控件设计实用的界面. Android中的视图都是继承Vi ...

  5. (转)Java 的swing.GroupLayout布局管理器的使用方法和实例

    摘自http://www.cnblogs.com/lionden/archive/2012/12/11/grouplayout.html (转)Java 的swing.GroupLayout布局管理器 ...

  6. Android 基础:常用布局 介绍 & 使用(附 属性查询)

    Android 基础:常用布局 介绍 & 使用(附 属性查询)   前言 在 Android开发中,绘制UI时常需各种布局 今天,我将全面介绍Android开发中最常用的五大布局 含 Andr ...

  7. Swing 混合布局

    案例一:Border边境边界 package swing; /** * swing 混合布局 */ import java.awt.*; import javax.swing.*; public cl ...

  8. WPF中的常用布局

    一 写在开头1.1 写在开头评价一门技术的好坏得看具体的需求,没有哪门技术是面面俱到地好. 1.2 本文内容本文主要内容为WPF中的常用布局,大部分内容转载至https://blog.csdn.net ...

  9. Android开发工程师文集-Fragment,适配器,轮播图,ScrollView,Gallery 图片浏览器,Android常用布局样式

    Android开发工程师文集-Fragment,适配器,轮播图,ScrollView,Gallery 图片浏览器,Android常用布局样式 Fragment FragmentManager frag ...

随机推荐

  1. forever 使用

    安装: $npm install -g forever y@y:ydkt$ forever start server/app.js warn: --minUptime not set. Default ...

  2. COJ 0342 逆序对(一)

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=312 试题描述: 给你一个大小为N的int数组A.请你统计有多少数对(Ai, ...

  3. 主席树套树状数组 动态区间第k小

    先打上代码以后更新解释 #include <cstdio> #include <iostream> #include <algorithm> #include &l ...

  4. BZOJ1524: [POI2006]Pal

    1524: [POI2006]Pal Time Limit: 5 Sec  Memory Limit: 357 MBSubmit: 308  Solved: 101[Submit][Status] D ...

  5. Android--广播BroadcastReceiver

    前言 Android四大组件,Activity.Service.ContentProvider.BroadcastReceiver,除了BroadcastReceiver之外,其他的在之前的博客中都有 ...

  6. 进程间通讯aidl

    进程间通讯(aidl) 1.首先定义一个接口 2.把这个接口的文件扩展名改为xxx.aidl 3.写一个MyService类继承自Service类重新里面的方法, 4.在MyService类定义一个内 ...

  7. git bash中避免在push时反复输入用户名和密码

    我用的是windows系统,这几天学着使用git时发现每次使用git push时每次都要输入一遍用户名和密码,感觉特烦,特意上网查了下,找到了简化方法.虽然不是原创,但至少算是加了点自己的心得和经验吧 ...

  8. 《Linear Algebra and Its Applications》-chaper2-矩阵代数-分块矩阵

    分块矩阵的概念: 在矩阵的实际应用中,为了形式的更加简化我们将一个较大的矩阵的内部进行一定的划分,使之成为几个小矩阵,然后在表大矩阵的时候,矩阵的内部元素就用小矩阵代替. 进行了这一步简化,我们就要分 ...

  9. migration vmware vms to openstack kvm 修改vmware windows scsi to ide

  10. 【iOS与EV3混合机器人编程一系列五个】iOS_WiFi_EV3_Library 解剖连接EV3

    在上一篇文章中.我们解说了怎样用开源码库CocoaAsyncSocket来实现iOS上的UDP和TCP数据通信.那么在本文中.我们将介绍在CocoaAsyncSocket的基础怎样使用UDP和TCP连 ...