Draw2d中的布局管理器Layout比较

本文探讨了在Eclipse GEF开发中,Draw2d库中常用的五种布局管理器:BorderLayout、ToolbarLayout、FlowLayout、GridLayout和XYLayout。由于在开发过程中遇到Figure显示问题,作者深入研究并发现Layout是关键。文章通过代码示例和效果展示,对比分析了各Layout的特点和用法。
摘要由CSDN通过智能技术生成

最近在研究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")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值