当前位置: 代码迷 >> Eclipse >> swt中用shell想在自定义选项卡上添加滚动面板使得有滚动效果解决方法
  详细解决方案

swt中用shell想在自定义选项卡上添加滚动面板使得有滚动效果解决方法

热度:20   发布时间:2016-04-23 13:34:09.0
swt中用shell想在自定义选项卡上添加滚动面板使得有滚动效果
菜鸟第一次发帖 我在eclipse上用swt添加了一个自定义选项卡的控件,然后希望能在上面有滚动条可以滚动,可是我查找滚动条的资料它的父面板全是shell 当被我改成了选项卡后就不能生效了 求解

ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setMinWidth(100);
scrolledComposite.setMinHeight(100);

Composite composite = new Composite(scrolledComposite, SWT.NONE);

tabItem.setControl(scrolledComposite);
composite.setLayout(new GridLayout(5, false));
composite.setSize(scrolledComposite.computeSiz(SWT.DEFAULT, SWT.DEFAULT));

scrolledComposite.setContent(composite);
这是我的代码

------解决方案--------------------
CTabFolder tabFolder = new CTabFolder(panel, SWT.LEFT);
tabFolder.setLayout(new FillLayout());
tabFolder.setTabHeight(KS.MAINCONTENT_TITLEHEIGHT);
tabFolder.setBackgroundImage(rm.getSkinImage(KS.CS_BG_WDLBAR));

CTabItem item = new CTabItem(tabFolder, SWT.NONE);
item.setText(" 你好 ");




Composite itcom = new Composite(tabFolder, SWT.BORDER);
itcom.setLayout(new FillLayout());
itcom.setBackground(rm.getColor(KS.COLOR_WHITE));


final ScrolledComposite sc = new ScrolledComposite(itcom, SWT.H_SCROLL | SWT.V_SCROLL);
final Composite infoPanel1 = new Composite(sc,SWT.NONE);



sc.setContent(infoPanel1);//设置受控面板
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);

infoPanel1.setLayout(new GridLayout(1,false));
for (int i = 0; i < 40; i++) {
Label label = new Label(infoPanel1, SWT.BORDER);
label.setText(" 你好 ");

}

sc.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Point r = infoPanel1.computeSize(SWT.DEFAULT, SWT.DEFAULT);
sc.setMinSize(sc.computeSize(r.x, r.y));
}
});


item.setControl(itcom);
  相关解决方案