版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、概述布局管理器的工作过程protected void addImpl(Component comp, Object constraints, int index) /*当我们删除组件时,要调用这个方法,而它要遍布容器内的所有组件,然后根据索引值调用remove(int *index)方法。*/public void remove(Component comp) /*根据索引值删除容器的组件,可以看到该方法调用了布局管理器的removeLayoutComponent()*/public void remove(int index) synchronized (getTreeLock() if (
2、index < 0 | index >= ncomponents) throw new ArrayIndexOutOfBoundsException(index);Component comp = componentindex;synchronized (getTreeLock() if (layoutMgr != null) /*通知布局管理器已经add了组件 */ if (layoutMgr instanceof LayoutManager2) (LayoutManager2)layoutMgr).addLayoutComponent(comp, constraints); e
3、lse if (constraints instanceof String) layoutMgr.addLayoutComponent(String)constraints, comp); synchronized (getTreeLock() if (comp.parent = this) Component component = ponent; for (int i = ncomponents; -i >= 0; ) if (componenti = comp) remove(i); if (layoutMgr != null) layoutMgr.removeLayoutComp
4、onent(comp); if (valid) invalidate(); /*返回容器当前的布局管理器*/public LayoutManager getLayout() /*这个是我们经常调用的方法,设置容器的布局管理器*/public void setLayout(LayoutManager mgr) public void doLayout() /让布局管理器进行布局组件Deprecatedpublic void layout() /* Invalidates the container. The container and all parents above it are marke
5、d as needing* to be laid out. This method can be called often, so it needs to execute quickly. */public void invalidate() LayoutManager layoutMgr = this.layoutMgr;/*取得容器的首选大小*/public Dimension getPreferredSize() return layoutMgr; layoutMgr = mgr; if (valid) invalidate(); layout(); LayoutManager layo
6、utMgr = this.layoutMgr; if (layoutMgr != null) layoutMgr.layoutContainer(this); if (layoutMgr instanceof LayoutManager2) LayoutManager2 lm = (LayoutManager2) layoutMgr; lm.invalidateLayout(this); super.invalidate(); return preferredSize(); 3Deprecatedpublic Dimension preferredSize() Dimension dim =
7、prefSize;if (dim = null | !(isPreferredSizeSet() | isValid() synchronized (getTreeLock() prefSize = (layoutMgr != null) ? layoutMgr.preferredLayoutSize(this) : super.preferredSize();dim = prefSize;if (dim != null)return new Dimension(dim);elsereturn dim;/*取得容器的最小大小*/public Dimension getMinimumSize()
8、 Deprecatedpublic Dimension minimumSize() Dimension dim = minSize;if (dim = null | !(isMinimumSizeSet() | isValid() synchronized (getTreeLock() minSize = (layoutMgr != null) ? layoutMgr.minimumLayoutSize(this) : super.minimumSize(); return minimumSize(); dim = minSize; if (dim != null)return new Dim
9、ension(dim);elsereturn dim;/*取得容器的最大大小*/布局管理器的实现AWT标准布局管理器自定义布局管理器import java.awt.Dimension;import java.awt.Insets;import java.awt.LayoutManager;/* author tianyistar*/public class ColumnLayout implements LayoutManager private int xInset = 5;private int yInset = 5;private int yGap = 2;public void add
10、LayoutComponent(String s, Component c) public void layoutContainer(Container c) Insets insets = c.getInsets();int height = yInset + insets.top;Component children = c.getComponents();Dimension compSize = null;for (int i = 0; i < children.length; i+) compSize = childreni.getPreferredSize();children
11、i.setSize(compSize.width, compSize.height);childreni.setLocation(xInset + insets.left, height);height += compSize.height + yGap;public Dimension minimumLayoutSize(Container c) /确定此容器的 insets,它指示容器边框的大小。Insets insets = c.getInsets();/Insets 对象是容器边界的表示形式。/它指定容器必须在其各个边缘留出的空间。这个空间可以是边界、空白空间或标题。 int height = yInset + insets.top;int width = 0 + insets.left + insets.right;Component children = c.getComponents();Dimension compSize = null;for (int i = 0; i < children.length; i+) compSize = childreni.getPreferredSize();height += compSize.height + yGap;width = Math.max(width, compSize.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 污水提升泵站检修方案
- 沥青路面封层施工操作手册
- 厂区智能化监控系统建设设计方案
- 室内精装修工程施工方案
- 水源热泵运行维护手册
- 重庆某锂电池回收利用项目可行性研究报告
- 桥梁承台墩身施工作业指导书
- 海港工程专项施工方案
- 城市口袋公园景观提升工程设计
- 装饰装修工程量统计计算手册
- 2026小学数学北师大版新教材培训:四至六年级教材解析
- 2026人教版小学三年级下册数学期末综合试卷3套(打印版+答案解析)
- 2026年巨量本地推初级题库
- 校本教材-无人机空气动力学与飞行原理
- T/CEC 193-2018 电力行业无人机巡检作业人员培训考核规范
- 生物医药研发项目计划书范例
- 医疗器械经营质量管理规范现场检查原则培训试题及答案
- 智能交通系统在公共交通线路优化中的应用可行性研究报告
- 第十届“雄鹰杯”小动物医师技能大赛备考试题库(附答案)
- 医院食品安全培训
- (正式版)DB14∕T 3563-2025 《 县域医共体慢病管理中心建设与运行规范》
评论
0/150
提交评论