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 ...
随机推荐
- JMS-activeMQ
参考资料: http://yuxisanren.iteye.com/blog/1912587 .JMS简介:JMS即Java Message Service,是Java 程序创建.发送.接收和读取企业 ...
- 史上最全前端面试题(含答案) - Web开发面试题
HTML+CSS 1.对WEB标准以及W3C的理解与认识 标签闭合.标签小写.不乱嵌套.提高搜索机器人搜索几率.使用外 链css和js脚本.结构行为表现的分离.文件下载与页面速度更快.内容能被更多的用 ...
- python文件_写入
1.输入的数据写入到一个文本: #这个写入操作不会将原来的数据覆盖掉 n=raw_input('请输入写入的文件数据:') fl2=open('g:/2.txt','a') fl2.write('\n ...
- AngularJS 基础教程一:
一:了解AngularJS AngularJS是一款非常优秀的前端高级 JS 框架,由 Misko Hevery 等人创建 2009 年被 Google 收购,用于其多款产品 有一个全职的开发团队继续 ...
- [OpenJudge] 百练2754 八皇后
八皇后 Description 会下国际象棋的人都很清楚:皇后可以在横.竖.斜线上不限步数地吃掉其他棋子.如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. ...
- 在Fedora 20下编译安装QEMU
由于OpenStack的流行,现在越来越多的人关注QEMU,最近发行了新版本1.7,下面就说Fedora下的安装过程: 首先需要安装基本的编译软件和git sudo yum install gcc m ...
- cf B. Vasily the Bear and Fly
http://codeforces.com/contest/336/problem/B #include <cstdio> #include <cstring> #includ ...
- hdu 1142 A Walk Through the Forest
http://acm.hdu.edu.cn/showproblem.php?pid=1142 这道题是spfa求最短路,然后dfs()求路径数. #include <cstdio> #in ...
- UltraChart画柱状图上面显示数值
http://www.cnblogs.com/kevin-h-wang/archive/2013/06/05/UltraChart.html 1.柱状图上显示数值 ? //第一种方法 this.Ult ...
- Populating Next Right Pointers in Each Node II 解答
Question Follow up for problem "Populating Next Right Pointers in Each Node". What if the ...