给Figure添加滚动条

Draw2d中有ScrollPane这样一个IFigure,它可以设置从不、一直、自动三种方式来现实滚动条,默认是自动。
实现步骤:
1、添加容器
panel = new Panel();
2、给容器添加布局(参照Draw2D布局,以便使用适合自己的布局)
3、在EditPart中将panel设置为ContentPanel

下面给出我的实现:
listboxFigure:
/*******************************************************************************
* Copyright (c) 2005-2011, Chinese Eclipse Community(CEC) All rights reserved.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.ceclipse.org
*
* Contributors:
* Ming.He <heming@ceclipse.com> - initial API and implementation
*******************************************************************************/
package org.cec.design.graphic.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.CompoundBorder;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.ScrollPane;
import org.eclipse.draw2d.ToolbarLayout;

/**
* TODO 此处填写 class 信息
*
* @author Ming.He
* @date 2011-4-5
*/
public class ListboxFigure extends ScrollPane {

private Panel panel;

public ListboxFigure() {
setOpaque(true);
setBackgroundColor(ColorConstants.white);
ToolbarLayout layout = new ToolbarLayout();
layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
layout.setStretchMinorAxis(false);
layout.setSpacing(2);
panel = new Panel();
panel.setBorder(new CompoundBorder(new LineBorder(), new MarginBorder(3)));
panel.setLayoutManager(layout);
setContents(panel);
}

public IFigure getContentFigure(){
return panel;
}

}


重写EditPart中实现getContentPane方法:
/* (non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getContentPane()
*/
//Override
public IFigure getContentPane() {
return ((ListboxFigure)getFigure()).getContentFigure();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值