swing常用布局
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常用布局的更多相关文章
- 第13章 Swing程序组件----常用布局管理器
在Swing中,每个组件在容器中都有一个具体的位置和大小,而在容器中摆放各种组件时很难判断其具体位置和大小.布局管理器提供了Swing组件安排.展示在容器中的方法及基本的布局功能. Swing提供的常 ...
- python:页面布局 后台管理页面之常用布局
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 常用布局,div竖直居中
常用两列布局,多列布局和div竖直居中 body { margin:; padding:; } .w200 { width: 200px; } .mar-left200 { margin-left: ...
- 跟我学android-android常用布局介绍
在上一章我们曾经谈到,Android平台的界面 是使用XML的方式设计的,然后在上一章我们只做了一个简单的界面,在这章,我们将介绍如何使用常用的控件设计实用的界面. Android中的视图都是继承Vi ...
- (转)Java 的swing.GroupLayout布局管理器的使用方法和实例
摘自http://www.cnblogs.com/lionden/archive/2012/12/11/grouplayout.html (转)Java 的swing.GroupLayout布局管理器 ...
- Android 基础:常用布局 介绍 & 使用(附 属性查询)
Android 基础:常用布局 介绍 & 使用(附 属性查询) 前言 在 Android开发中,绘制UI时常需各种布局 今天,我将全面介绍Android开发中最常用的五大布局 含 Andr ...
- Swing 混合布局
案例一:Border边境边界 package swing; /** * swing 混合布局 */ import java.awt.*; import javax.swing.*; public cl ...
- WPF中的常用布局
一 写在开头1.1 写在开头评价一门技术的好坏得看具体的需求,没有哪门技术是面面俱到地好. 1.2 本文内容本文主要内容为WPF中的常用布局,大部分内容转载至https://blog.csdn.net ...
- Android开发工程师文集-Fragment,适配器,轮播图,ScrollView,Gallery 图片浏览器,Android常用布局样式
Android开发工程师文集-Fragment,适配器,轮播图,ScrollView,Gallery 图片浏览器,Android常用布局样式 Fragment FragmentManager frag ...
随机推荐
- Web Service相关工具的配置
近期在学习Web Service Testing,使用到了soapUI这个工具,但是在学习之前,需要搭建Web Service环境,其中有关数据库的连接问题花费了我好多时间,主要还是自己对于很多配置不 ...
- 构建高可用web站点学习(一)
单个服务器如何处理请求 web服务器最简单的形式就是一个程序,它侦听HTTP请求,在收到一个HTTP请求之后做出回复.当然在接收请求后服务器所做的东西是我们关注的焦点.在下文中也会提及到node是如何 ...
- ZedGraph控件生成饼图、拆线图和柱状图例程
这几天做了个自己觉得还蛮NB的功能,在GRID中选中一块数据,然后右键菜单即可生成三种图形,还可以互相切换,对了,饼图还添加了鼠标点击分离的处理,大致如图: 用的控件就是ZedGraph,我把它继承封 ...
- 【技术贴】xp任务栏字体变大变小
今天远程到服务器上,发现任务栏字体变小了,百度了很久,发现百度就是个渣渣,什么答案都搜不到.就自己摸索了一下. 方法一: 桌面右击属性-外观-字体大小, 下拉匡 方法二 :桌面右击[属性]-[外观]- ...
- 使用Protractor进行AngularJS e2e测试案例
环境: y@y:karma-t01$ protractor --version Version y@y:karma-t01$ node -v v4.2.2 y@y:karma-t01$ y@y:kar ...
- forever 使用
安装: $npm install -g forever y@y:ydkt$ forever start server/app.js warn: --minUptime not set. Default ...
- poj 2892 &&hdu 1540 Tunnel Warfare
http://poj.org/problem?id=2892 #include <cstdio> #include <cstring> #include <algorit ...
- poj 2195Going Home
http://poj.org/problem?id=2195 #include<cstdio> #include<cstring> #include<cmath> ...
- nterrupt 和 using 在C51中断中的使用
8051系列MCU的基本结构包括:32个I/O口(4 组8bit 端口):两个16位定时计数器:全双工串行通信:6个中断源(2个外部中断.2个定时/计数器中断.1个串口输入/输出中断),两级中断优先级 ...
- [Javascript] Intro to Recursion
Recursion is a technique well suited to certain types of tasks. In this first lesson we’ll look at s ...