当前位置:网站首页>【SWT组件】内容滚动组件 ScrolledComposite
【SWT组件】内容滚动组件 ScrolledComposite
2022-07-05 10:13:00 【小子宝丁】
目的
记录 ScrolledComposite
使用方法,总结重要。
实践
ScrolledComposite 类注解出给出了一个Demo,其代码如下:
package com.xzbd.swt01.test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class CompositeTest {
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 = 1;
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 = 1;
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 ();
}
}
总结
demo给出了两个内容滚动的案例,分别展示了设置内容容器大小和设置最小尺寸两种方法,其中重要的方法有:
- 实例
ScrolledComposite
时在style中指定横向或纵向可滚动SWT.H_SCROLL
、SWT.V_SCROLL
。 - 创建一个子内容并指定给
ScrolledComposite
Composite c1 = new Composite(sc1, SWT.NONE);
sc1.setContent(c1);
- 当
ScrolledComposite
的内容发生变化时要及时更新内容容器,或ScrolledComposite
本身。
// reset size of content so children can be seen - method 1
c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
c1.layout();
或
// reset the minimum width and height so children can be seen - method 2
sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
c2.layout();
边栏推荐
- “军备竞赛”时期的对比学习
- Cerebral cortex: directed brain connection recognition widespread functional network abnormalities in Parkinson's disease
- Singleton mode encapsulates activity management class
- @Serializedname annotation use
- 官网给的这个依赖是不是应该为flink-sql-connector-mysql-cdc啊,加了依赖调
- WorkManager学习一
- "Everyday Mathematics" serial 58: February 27
- WorkManager的学习二
- 横向滚动的RecycleView一屏显示五个半,低于五个平均分布
- 请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
猜你喜欢
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
How to plan the career of a programmer?
自动化规范检查软件如何发展而来?
Constraintlayout officially provides rounded imagefilterview
Detailed explanation of the use of staticlayout
AD20 制作 Logo
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
5G NR系统架构
How does redis implement multiple zones?
WorkManager学习一
随机推荐
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
Singleton mode encapsulates activity management class
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
How can PostgreSQL CDC set a separate incremental mode, debezium snapshot. mo
SAP UI5 ObjectPageLayout 控件使用方法分享
flink cdc不能监听mysql日志,大家遇到过这个问题吧?
ByteDance Interviewer: how to calculate the memory size occupied by a picture
Pseudo class elements -- before and after
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
QT VT100 parser
手机厂商“互卷”之年:“机海战术”失灵,“慢节奏”打法崛起
ConstraintLayout官方提供圆角ImageFilterView
自动化规范检查软件如何发展而来?
The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five
Who is the "conscience" domestic brand?
如何写出高质量的代码?
Window下线程与线程同步总结
Z-blog template installation and use tutorial
Apple 5g chip research and development failure? It's too early to get rid of Qualcomm
5g NR system architecture