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 ...
随机推荐
- vc2015编译protobuf
下载地址:https://github.com/google/protobuf 1.编译通过cmake生成sln文件来编译用cmd命令 cd 到3.0.0-beta-4\cmake mkdir bui ...
- [Search Engine] Compression in Inverted Index
最近在学一些搜索引擎的内容,感觉挺费劲,所以就用博客当做自己的笔记,遇到一些需要整理的部分,就在这里整理一下. 今天的内容是对inverted index进行压缩.核心思想,用我自己的话来总结,就是“ ...
- 使用ganymed-ssh2-build通过ssh获得远程服务器参数
1.项目中需要检测到几台远程服务器的参数,差了很多资料,决定用的这个 2.jar包:ganymed-ssh2-build210.jar 3.原理:向远程linux服务器发送脚本命令,得到该台服务器的信 ...
- 一个很简单的jQuery插件实例教程(菜鸟级)
很多公司的前端设计开发人员都是女孩子,而这些女孩子很多JavaScript技能都不是很好.而前端开发过程中,JavaScript技能又是必不可少的.所以,如果前端小MM正在为某个JavaScript效 ...
- python 远程统计文件
#!/usr/bin/python #encoding=utf-8 import time import os import paramiko import multiprocessing #统计文件 ...
- CC2530 PWM波形产生。
1.使用TIM3_CC1,相关联引脚P1_7 #define GPIOPWM() do{P1SEL |= 0x80;}while(0);#define GPIOCLOSEPWM() do{P1SEL ...
- DataTables给每一列添加下拉框搜索
$(document).ready(function() { $('#example').DataTable( { initComplete: function () { var api = this ...
- Effective Java提升Code Coverage代码涵盖率 - 就是爱Java
虽然我们已经有了测试程序,但是如何得知是否已完整测试了主程序?,透过Code Coverage代码涵盖率,我们可以快速地得知,目前系统中,有多少程序中被测试过,不考虑成本跟投资效益比,涵盖率越高,代表 ...
- strace基本操作
可以发现很多真正在系统层面发生的调用,以及很细微的返回错误信息,用于调试工作.(比如,软件出错,或是性能变慢...) strace -p 32000 -o strace.txt 基本上完整的用法是这样 ...
- PADSPOWERPCB中怎样去隐藏一些PIN脚
由于一些板,尤其是U盘等面积很小的板,FLASH中只使用了为数不多的几个PIN,为了可以让其它PIN下面可以走线,增加GND网络的面积,所以实际操作中要隐藏一些PIN.这就需要怎么操作呢! 我们要做的 ...