目的

记录 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 1final 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 2final 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 1c1.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 2sc2.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_SCROLLSWT.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();

【SWT组件】内容滚动组件 ScrolledComposite相关推荐

  1. Delphi TScrollBar 用于滚动窗口、组件内容

    滚动条组件(TScrollBar)此组件是一个Windows滚动条,用于滚动窗口.组件内容.许多控制有滚动条属性,它们把滚动条作为自己的一部分,对于没有完整滚动条的控制,TScrollBar组件提供了 ...

  2. 过滤内容字段_巧用参数组件和过滤组件,教你快速定位目标数据

    在我们日常制作报表分析过程中,总会遇到各种问题,比如,如何解决复杂报表问题,我们学会了使用多粒度表达式.那在报表分析中如何根据业务指标展现我们想要的数据呢?这里就需要对数据进行过滤,今天我们将为大家介 ...

  3. 【精讲】微信小程序 基础内容(组件)入门

    目录 第一部分:滚动菜单内容 第二部分:轮播图内容 第三部分:常用基础组件 第四部分:数据操作 第一部分:滚动菜单内容 wxml内容: <!-- scroll-y是纵向滚动 --> < ...

  4. 使用Element的 InfiniteScroll 无限滚动组件报错

    一.问题描述 在使用Element的InfiniteScroll 无限滚动时候出现以下错误: TypeError: Failed to execute 'observe' on 'MutationOb ...

  5. Element UI - v-infinite-scroll无限滚动组件

    一.v-infinite-scroll无限滚动组件使用详解 1.v-infinite-scroll="load" //load无限滚动加载的方法2.infinite-scroll- ...

  6. 【ElementUI】InfiniteScroll 无限滚动组件在部分浏览器中滚动失效 的 解决方案

    ElementUI 官网 InfiniteScroll 使用:https://element.eleme.cn/#/zh-CN/component/infiniteScroll 首先先叙述一下需求,说 ...

  7. 【react】InfiniteScroll 滚动组件

    在data.d.ts中定义父组件所需要传的值 import { ReactNode } from 'react' type PullStatus = 'pulling' | 'canRelease' ...

  8. vue 文字上下循环滚动_基于 Vue 无缝滚动组件Vue-Seamless-Scroll

    今天给小伙伴们推荐一款超棒的Vue无缝滚动组件VueSeamlessScroll. vue-seamless-scroll 基于 vue.js 构建的简单实用的无缝滚动组件.满足丰富的配置需求,支持上 ...

  9. 【Flutter】监听滚动动作 控制组件 透明度渐变 ( 移除顶部状态栏空白 | 帧布局组件 | 透明度组件 | 监听滚动组件 )

    文章目录 前言 一.移除顶部状态栏空白 二.帧布局组件 三.透明度组件 四.监听滚动事件 五.完整代码示例 六.相关资源 前言 在上一篇博客 [Flutter]Banner 轮播组件 ( flutte ...

最新文章

  1. (备忘)Java数据类型中String、Integer、int相互间的转换
  2. 小米造车150天:烈火烹油第一枪
  3. Linux ls -l文件列表权限详解
  4. mysql 远程登录权限
  5. Redis笔记之常用命令
  6. CURL HTTPS POST
  7. leetcode406. 根据身高重建队列
  8. tensorflow中的Supervisor
  9. 云开发0基础训练营第二期热力来袭!
  10. 启动activemq_「Java」 - SpringBoot amp; ActiveMQ
  11. php 网页转pdf
  12. Python 直接赋值、浅拷贝和深度拷贝全解析
  13. 安装独立版本的 Adobe Community Help
  14. 西安高铁“洋班组” 助力新春运
  15. 转载:详解C中volatile关键字
  16. 京东支付首席架构师“泄密”京东支付系统架构
  17. hutool工具私人学习笔记
  18. 油猴(Tampermonkey)插件+脚本+IDM=百度网盘高速下载
  19. 迅雷手机版苹果版_「9月22日」最新 苹果IOS手机迅雷Beta版证书修复版 安卓不限速...
  20. java逆向_Java逆向入门(一)

热门文章

  1. 【数据结构】树与二叉树
  2. 多方法解决设置width:100%再设置margin或padding溢出的问题
  3. jquery mobile java_jQuery Mobile 快速入门
  4. halcon C++编程 第6讲 HVector(tcy)
  5. 要不,和机器聊聊?-- 小谈Bot系统
  6. android开发ssh框架搭建,基于SSH框架的Android系统的研究
  7. Python使用openpyxl库操作Excel之(二)访问已有的Excel文件
  8. 1631哥德巴赫猜想
  9. 数据服务器之raid1使用
  10. linux下ftp教程视频,linux FTP服务器wmv视频教程