package cn.com.chengang.swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class ScrolledComposite1 {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
// ---------创建窗口中的其他界面组件-------------
// 定义一个ScrolledComposite,式样为深陷型、带水平滚动条、带垂直滚动条
ScrolledComposite scrolledComposite = new ScrolledComposite(shell,
SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setBounds(12, 6, 256, 148);
// 定义一个面板Composite,用此面板来容纳其他的组件
Composite composite = new Composite(scrolledComposite, SWT.NONE);
// 这里没用setBounds是因为composite和scrolledComposite的左上角自动重合
composite.setSize(326, 237);// 设置composite面板的大小
scrolledComposite.setContent(composite);// 设置composite被scrolledComposite控制
// 建立八个文本框,以横二竖四排列。这里将Text的定义和Text的定位两个语句合写在了一起
new Text(composite, SWT.BORDER).setBounds(12, 13, 132, 40);
new Text(composite, SWT.BORDER).setBounds(155, 13, 132, 40);
new Text(composite, SWT.BORDER).setBounds(10, 70, 132, 40);
new Text(composite, SWT.BORDER).setBounds(155, 70, 132, 40);
new Text(composite, SWT.BORDER).setBounds(10, 120, 132, 40);
new Text(composite, SWT.BORDER).setBounds(155, 120, 132, 40);
new Text(composite, SWT.BORDER).setBounds(10, 170, 132, 40);
new Text(composite, SWT.BORDER).setBounds(156, 171, 132, 40);
// -----------------END------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
<--------------------2-------------------->
public static void main(String[] args) {
Display display = new Display();
Color red = display.getSystemColor(SWT.COLOR_RED);
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
// set the size of the scrolled content - method 1
final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
final Composite c1 = new Composite(sc1, SWT.NONE);
sc1.setContent(c1);
c1.setBackground(red);
GridLayout layout = new GridLayout();
layout.numColumns = 4;
c1.setLayout(layout);
Button b1 = new Button(c1, SWT.PUSH);
b1.setText("first button");
c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
// set the minimum width and height of the scrolled content - method 2
final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
sc2.setExpandHorizontal(true);
sc2.setExpandVertical(true);
final Composite c2 = new Composite(sc2, SWT.NONE);
sc2.setContent(c2);
c2.setBackground(blue);
layout = new GridLayout();
layout.numColumns = 4;
c2.setLayout(layout);
Button b2 = new Button(c2, SWT.PUSH);
b2.setText("first button");
sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Button add = new Button(shell, SWT.PUSH);
add.setText("add children");
final int[] index = new int[] { 0 };
add.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
index[0]++;
Button button = new Button(c1, SWT.PUSH);
button.setText("button " + index[0]);
// reset size of content so children can be seen - method 1
c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
c1.layout();
button = new Button(c2, SWT.PUSH);
button.setText("button " + index[0]);
// reset the minimum width and height so children can be seen - method 2
sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
c2.layout();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
<----------------------3------------------------>
如果是 FormLayout composite1Layout = new FormLayout();
composite1.setLayout(composite1Layout);
如果设置了FormLayout ,那么上面的控件也需要设置为FormLayout。否则就将无法显示。
无法显示的情况
cTabItem2 = new CTabItem(cTabFolder1, SWT.NONE);
cTabItem2.setText("Method Comment");
{
composite6 = new Composite(cTabFolder1, SWT.NONE);
FormLayout composite6Layout = new FormLayout();
composite6.setLayout(composite6Layout);
cTabItem2.setControl(composite6);
{
scrolledComposite1 = new ScrolledComposite(composite6, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
FormData scrolledComposite1LData = new FormData(); // *关键在此
scrolledComposite1LData.width = 539;
scrolledComposite1LData.height = 215;
scrolledComposite1LData.left = new FormAttachment(0, 1000, 2);
scrolledComposite1LData.top = new FormAttachment(0, 1000, 2);
scrolledComposite1.setLayoutData(scrolledComposite1LData);
{
composite7 = new Composite(scrolledComposite1, SWT.NONE);
scrolledComposite1.setContent(composite7);
composite7.setBounds(0, 0, 560, 303);
{
label6 = new Label(composite7, SWT.NONE);
label6.setText("Method Name:");
label6.setBounds(35, 30, 160, 20);
label6.setFont(SWTResourceManager.getFont("宋体", 12, 0, false, false));
}
{
text6 = new Text(composite7, SWT.BORDER);
text6.setText("text6");
text6.setBounds(200, 60, 220, 20);
text6.setFont(SWTResourceManager.getFont("宋体", 12, 0, false, false));
}
{
button3 = new Button(composite7, SWT.PUSH | SWT.CENTER);
button3.setText("Seek..");
button3.setBounds(439, 66, 53, 23);
}
}
}
}
分享到:
相关推荐
Jfreechart提供的SWT接口,并不支持滚动条,本资源实现了这个方法
ScrolledComposite自动出现最适合大小的滚动条代码
SWT的例子,包括按钮、文本框、树、列表、进度条、滚动条以及利用控件进行其他的一些基本的逻辑运算等
本包包含基础组件的demo及属性介绍,扩展组件,自定义组件,滚动条,分割线,分组、布局、选项卡等以及高级组件的应用demo
SWT实现图片列表预览, 封装了一个用于展示图片的类,根据构造方法可以设置显示的行数及列数。根据设置的宽高进行自适应,可以实现滚动条,选择,查看,全选,反选,图片大小自适应等其他操作。
scrollbar jfreechart
6.7.1 设置滚动条的样式 96 6.7.2 滚动面板的其他方法 97 6.8 本章小结 97 第7章 SWT布局管理器 98 7.1 布局管理器概述 98 7.1.1 绝对定位 98 7.1.2 托管定位 98 7.1.3 常见的布局管理器 100 7.2 ...
SWT那些包的用法和详细说明。 Shell控件就是窗口对象类,通过...Shell类是继承于Composite类,而Composite类继承了Scrollable类,所以可以在他上面摆放其他控件、设置排列方式、添加滚动条、添加最大最小关闭按钮。
anicon2.zip 在窗口的标题条上显示动画图标(2KB)<END><br>10,simple.zip 一般用途的分隔器类(43KB)<END><br>11,outlook.zip OutLook风格的分隔条(59KB)<END><br>12,appbar1.zip 实现桌面的工具条...
[ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP...
[ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP...
[ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP...
[ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP...
日历表格面板 [ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP连接...
日历表格面板 [ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP连接...
[ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP...
[ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP...