0
点赞
收藏
分享

微信扫一扫

SWT组件介绍

陌岛 2022-10-17 阅读 129


  • 介绍

本文介绍SWT中一些组件的使用方法。

  • ScrolledComposite

[caption id="attachment_2688" align="aligncenter" width="188"]​​​​ ScrolledComposite[/caption]

[codesyntax lang="java"]


/**
* Copyright By suren.
* You can get more information from my website:
* http://surenpi.com
*/
package org.suren.swt.test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* @author suren
* @date 2015年9月30日 下午4:57:34
*/
public class ScrolledTest
{

/**
* @param args
*/
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

shell.setSize(200, 100);

ScrolledComposite scroll = new ScrolledComposite(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
Composite composite = new Composite(scroll, SWT.NULL);
composite.setLayout(new RowLayout());

new Button(composite, SWT.PUSH).setText("one");
new Button(composite, SWT.PUSH).setText("one");
new Button(composite, SWT.PUSH).setText("one");
new Button(composite, SWT.PUSH).setText("one");
new Button(composite, SWT.PUSH).setText("one");
new Button(composite, SWT.PUSH).setText("one");

//下面两句必须有
scroll.setContent(composite);
composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();
}

}


[/codesyntax]


举报

相关推荐

0 条评论