当前位置:网站首页>[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
ScrolledComposite
At 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
ScrolledComposite
The content container should be updated in time when the content of changes occur , orScrolledComposite
In 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();
边栏推荐
猜你喜欢
Detailed explanation of DDR4 hardware schematic design
Go语言-1-开发环境配置
Based on shengteng AI Aibi intelligence, we launched a digital solution for bank outlets to achieve full digital coverage of information from headquarters to outlets
Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
2022 Pengcheng cup Web
Detailed explanation of MATLAB cov function
[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output
Wechat nucleic acid detection appointment applet system graduation design completion (8) graduation design thesis template
关于vray 5.2的使用(自研笔记)(二)
基于昇腾AI丨以萨技术推出视频图像全目标结构化解决方案,达到业界领先水平
随机推荐
上拉加载原理
iframe
Leetcode 185 All employees with the top three highest wages in the Department (July 4, 2022)
Go-3-第一个Go程序
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
msfconsole命令大全,以及使用说明
【广告系统】增量训练 & 特征准入/特征淘汰
DGL中异构图的一些理解以及异构图卷积HeteroGraphConv的用法
Use bat command to launch common browsers with one click
Function///
关于vray 5.2的使用(自研笔记)
Question bank and answers of special operation certificate examination for main principals of hazardous chemical business units in 2022
Go project practice - parameter binding, type conversion
购买小间距LED显示屏的三个建议
Based on shengteng AI Yisa technology, it launched a full target structured solution for video images, reaching the industry-leading level
Intelligent metal detector based on openharmony
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
Web3基金会「Grant计划」赋能开发者,盘点四大成功项目
小红书自研KV存储架构如何实现万亿量级存储与跨云多活
Cross page communication