当前位置:网站首页>[SWT component] content scrolledcomposite
[SWT component] content scrolledcomposite
2022-07-05 11:09:00 【Boy Baoding】
Purpose
Record ScrolledComposite Usage method , Summary important .
practice
ScrolledComposite Class annotation gives a Demo, The code is as follows :
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 ();
}
}
summary
demo Two cases of content scrolling are given , It shows two methods of setting the size of content container and setting the minimum size , The important methods are :
- example
ScrolledCompositeAt the time style Specify horizontal or vertical scrollableSWT.H_SCROLL、SWT.V_SCROLL. - Create a sub content and assign it to
ScrolledComposite
Composite c1 = new Composite(sc1, SWT.NONE);
sc1.setContent(c1);
- When
ScrolledCompositeThe content container should be updated in time when the content of changes occur , orScrolledCompositeIn itself .
// reset size of content so children can be seen - method 1
c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
c1.layout();
or
// reset the minimum width and height so children can be seen - method 2
sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
c2.layout();
边栏推荐
- Sqlserver regularly backup database and regularly kill database deadlock solution
- 数据类型 ntext 和 varchar 在not equal to 运算符中不兼容 -九五小庞
- Go language-1-development environment configuration
- Operation of simulated examination platform of special operation certificate examination question bank for safety production management personnel of hazardous chemical production units in 2022
- Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
- A mining of edu certificate station
- Go-3-第一个Go程序
- [JS learning notes 54] BFC mode
- 数组、、、
- Common functions of go-2-vim IDE
猜你喜欢
![[Oracle] use DataGrid to connect to Oracle Database](/img/4f/886378667889f730eaed39b97f0a39.png)
[Oracle] use DataGrid to connect to Oracle Database

Three paradigms of database

Detailed explanation of DDR4 hardware schematic design

Repair animation 1K to 8K

如何让全彩LED显示屏更加节能环保

R3live series learning (IV) r2live source code reading (2)

DDR4硬件原理图设计详解

谈谈对Flink框架中容错机制及状态的一致性的理解

7.2每日学习4

The first product of Sepp power battery was officially launched
随机推荐
Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
Go-3-the first go program
[Oracle] use DataGrid to connect to Oracle Database
Share Net lightweight ORM
Stop saying that microservices can solve all problems!
基于昇腾AI丨以萨技术推出视频图像全目标结构化解决方案,达到业界领先水平
[JS learning notes 54] BFC mode
数据类型 ntext 和 varchar 在not equal to 运算符中不兼容 -九五小庞
LSTM applied to MNIST dataset classification (compared with CNN)
Advanced scaffold development
Go语言-1-开发环境配置
【广告系统】增量训练 & 特征准入/特征淘汰
Web Security
Repair animation 1K to 8K
Intelligent metal detector based on openharmony
SQL Server monitoring statistics blocking script information
四部门:从即日起至10月底开展燃气安全“百日行动”
Go project practice - Gorm format time field
MFC pet store information management system
Variables///