首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

给Figure增添滚动条

2012-10-30 
给Figure添加滚动条Draw2d中有ScrollPane这样一个IFigure,它可以设置从不、一直、自动三种方式来现实滚动条,

给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() *///Overridepublic IFigure getContentPane() {return ((ListboxFigure)getFigure()).getContentFigure();}

热点排行