Draw2d中的布局管理器Layout比较
最近在研究Eclipse中的GEF开发,在跟着GEF-whole-upload教程做一个GEF应用程序的例子时,发现Figure上的控件无法显示,谷歌了很久也没找到解决方案,最后终于发现是Layout的问题。同时发现还没有人进行过这方面的研究,于是打算写一篇文章对各种Layout进行比较。由于GEF的绘图部分使用的是Draw2d,因此本文是关于Draw2d中的Layout比较。
Draw2d中常用的Layout有BorderLayout、ToolbarLayout、FlowLayout、GridLayout、XYLayout。它们都继承于AbstractLayout,类图如下:
下面本文将对这些Layout的用法进行说明。
BorderLayout
BorderLayout是按五个区域进行布局,即上下左右中。代码如下:
protected IFigure createFigure() {
// TODO Auto-generated method stub
Figure figure = new Figure();
figure.setLayoutManager(new BorderLayout());
Label label1 = new Label();
label1.setText("test1");
figure.add(label1, BorderLayout.LEFT);
Label label2 = new Label();
label2.setText("test2");
figure.add(label2, BorderLayout.RIGHT);
Label label3 = new Label();
label3.setText("test3");
figure.add(label3, BorderLayout.TOP);
Label label4 = new Label();
label4.setText("test4");
figure.add(label4, BorderLayout.BOTTOM);
Label label5 = new Label();
label5.setText("test5");
figure.add(label5, BorderLayout.CENTER);
return figure;
}
效果如下:
ToolbarLayout
protected IFigure createFigure() {
// TODO Auto-generated method stub
Figure figure = new Figure();
ToolbarLayout layout = new ToolbarLayout();
layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
layout.setStretchMinorAxis(false);
layout.setSpacing(2);
figure.setLayoutManager(layout);
Label label1 = new Label();
label1.setText("test1");
figure.add(label1);
Label label2 = new Label();
label2.setText("test2");
figure.add(label2);
Label label3 = new Label();
label3.setText("test3");
figure.add(label3);
Label label4 = new Label();
label4.setText("test4");
figure.add(label4);
Label label5 = new Label();
label5.setText("test5");
figure.add(label5);
return figure;
}
效果如下:
FlowLayout
protected IFigure createFigure() {
// TODO Auto-generated method stub
Figure figure = new Figure();
FlowLayout flowLayout = new FlowLayout(true);//水平
flowLayout.setMinorSpacing(20);
flowLayout.setMajorAlignment(FlowLayout.ALIGN_TOPLEFT);
figure.setLayoutManager(flowLayout);
Label label1 = new Label();
label1.setText("test1");
figure.add(label1);
Label label2 = new Label();
label2.setText("test2");
figure.add(label2);
Label label3 = new Label();
label3.setText("test3");
figure.add(label3);
Label label4 = new Label();
label4.setText("test4");
figure.add(label4);
Label label5 = new Label();
label5.setText("test5");
figure.add(label5);
return figure;
}
效果如下:
GridLayout
protected IFigure createFigure() {
// TODO Auto-generated method stub
Figure figure = new Figure();
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
figure.setLayoutManager(gridLayout);
Label label1 = new Label();
label1.setText("test1");
figure.add(label1);
GridData label_gd1 = new GridData();
label_gd1.widthHint = 50;
label_gd1.heightHint = 50;
gridLayout.setConstraint(label1, label_gd1);
Label label2 = new Label();
label2.setText("test2");
figure.add(label2);
Label label3 = new Label();
label3.setText("test3");
figure.add(label3);
Label label4 = new Label();
label4.setText("test4");
figure.add(label4);
Label label5 = new Label();
label5.setText("test5");
figure.add(label5);
return figure;
}
效果如下:
XYLayout
protected IFigure createFigure() {
// TODO Auto-generated method stub
Figure figure = new Figure();
figure.setLayoutManager(new XYLayout());
Label label1 = new Label();
label1.setText("test1");
figure.add(label1, new Rectangle(0, 0, 50, 50));
Label label2 = new Label();
label2.setText("test2");
figure.add(label2, new Rectangle(25, 25, 50, 50));
Label label3 = new Label();
label3.setText("test3");
figure.add(label3, new Rectangle(50, 50, 50, 50));
Label label4 = new Label();
label4.setText("test4");
figure.add(label4, new Rectangle(75, 100, 50, 50));
Label label5 = new Label();
label5.setText("test5");
figure.add(label5, new Rectangle(40, 75, 50, 50));
return figure;
}
效果如下:
Draw2d中的布局管理器Layout比较的更多相关文章
- 第六章 Qt布局管理器Layout
第六章 Qt布局管理器Layout 大家有没有发现一个现象,我们放置一个组件,给组件最原始的定位是给出这个控件的坐标和宽高值,这样Qt就知道这个组件的位置.当用户改变窗口的大小,组件还静静地呆在原来的 ...
- JAVA中GridBagLayout布局管理器应用详解
很多情况下,我们已经不需要通过编写代码来实现一个应用程序的图形界面,而是通过强大的IDE工具通过拖拽辅以简单的事件处理代码即可很轻松的完成.但是我们不得不面对这样操作存在的一些问题,有时候我们希望能够 ...
- 【java】浅析java组件中的布局管理器
这篇博文笔者介绍一下java组件中,常用的布局管理器.java组件中的布局方式有好几十种,所有的这些布局管理器都实现了java.awt.LayoutManager接口.接下来笔者介绍一下常用的5种布局 ...
- Qt中的布局管理器
1. 布局管理器提供相关的类对界面组件进行布局管理,能够自动排列窗口中的界面组件,窗口变化后能自动更新界面组件的大小. 2. QLayout是Qt布局管理器的抽象基类,通过继承QLayout实现了功能 ...
- GridBagLayout:网格包布局管理器
GridBagLayout:网格包布局管理器 GridBagLayout可以说是布局管理器Layout中最复杂的一个,其中涉及到的参数也比较得多,比如说: GridBagConstraints g ...
- 【Android 应用开发】AndroidUI设计之 布局管理器 - 详细解析布局实现
写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...
- Swing——布局管理器
前言 在编写图形界面时,总是需要考虑的就是组件放在哪里,组件怎么大才合适.在Swing中就有现成的布局管理器帮我们做这些事情,我们不必写代码去一一安排.下面将介绍什么是布局管理器.Swing中常用布局 ...
- AndroidUI设计之 布局管理器 - 详细解析布局实现
写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...
- 二、Android应用的界面编程(二)布局管理器
一.线性布局所有布局都可以作为容器类使用,因此可以调用多个重载的addView()向布局管理器中添加组件.实际上,我们完全可以用一个布局管理器嵌套到其他布局管理器中---因为布局管理器也继承了View ...
随机推荐
- Python学习(一) Python安装配置
我本身是Java程序猿,听说Python很强大,所以准备学习一下Python,虽说语言都是相同的,但java跟python肯定还是有区别的.希望在此记录一下自己的学习过程. 目前,Python分2.X ...
- 使用grid++report打印选中行
接上一篇<hibernate+spring+mvc+Easyui框架模式下使用grid++report的总结>对grid++report做进一步开发 先写一下实现流程: 1.默认为全部载入 ...
- easy ui 实现gridview效果
前台: // 加载审批步骤列表 function FillStep(flowID) { $('#tbStepList').datagrid({ url: "/System/ApproverS ...
- java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils Caused by: java.lang.ClassNotFou ...
- 【转】sqlmap用户手册
http://192.168.136.131/sqlmap/mysql/get_int.php?id=1 当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数2.判断可以用那种SQL注入 ...
- double类型如何保留2为小数
double d=12.2121;string str = d.ToString("F2"); double x = 29.982;Console.WriteLine(x.ToSt ...
- 阻碍android程序员发展的几个原因
1应该少看网上的android开发相关技术帖子,一个是错误很多,表达也不清楚,很多都是拷贝来拷贝去的.二个是技术变迁快,很多都过时了,经常看android技术相关帖子,养成了一种惰性,遇到问题不是去看 ...
- Walls and Gates 解答
Question You are given a m x n 2D grid initialized with these three possible values. -1 - A wall or ...
- 浅谈JS数据类型存储问题
背景 一个经典的问题,先抛出来给大伙看看: var a = "黑MAO"; var b = a; var c = new Object(); var d = c; a ...
- Python开发过程中17个坑
一.不要使用可变对象作为函数默认值 复制代码代码如下: In [1]: def append_to_list(value, def_list=[]): ...: def_list. ...