版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年工业水处理公司生产现场6S与水处理标准化管理细则
- 2026年工业水处理公司客户水质满意度调查与改进管理制度
- 2026年福建省厦门市集美高中高三适应性生物试题考试试卷1含解析
- 陕西省育才中学2025-2026学年高三第三次(4月)联考生物试题理试题含解析
- 黑龙江省克东一中、克山一中等五校联考2026年高三生物试题期初模拟卷(1)含解析
- 2026年安徽省天长市关塘中学第二学期高三期末考试生物试题试卷含解析
- 2026年西藏自治区昌都市第三高级中学高三5月考化学试题含解析
- 云南省大理新世纪中学2026年高三复习统一检测试题化学试题含解析
- 2026年长沙市重点中学高考生物试题仿真卷:生物试题试卷(2)含解析
- 2026年湖南大众传媒职业技术学院单招综合素质笔试备考试题含详细答案解析
- 生产过程监督管理制度
- 血液灌流在维持性血液透析患者中的临床应用专家共识(2025年版)
- 2026年烟台汽车工程职业学院单招综合素质笔试备考试题带答案解析
- 涉密人员社交媒体使用保密指南
- 项目纸打印合同范本
- 传染病影像学课件
- 研发资料规范管理制度(3篇)
- GB/T 16770.1-2025整体硬质合金直柄立铣刀第1部分:型式与尺寸
- 工业产品销售单位质量安全日管控周排查月调度检查记录表
- 年龄段护理知识培训内容课件
评论
0/150
提交评论