JavaGUI之SWT框架 【SashForm CBanner】

文章目录

SashForm 分割窗

SashForm分割窗,能够将容器面板进行切割,分为两块。SashForm分割的方向有两种,一种是水平分割,另一种是垂直分割。

SashForm的创建方式如下

java 复制代码
// 创建分割窗口
SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);

// 创建窗口1
Composite c1 = new Composite(sashForm, SWT.BORDER);
c1.setLayout(new FillLayout());
new Text(c1, SWT.NONE).setText("窗口1");
// 创建窗口2
Composite c2 = new Composite(sashForm, SWT.BORDER);
c2.setLayout(new FillLayout());
new Text(c2, SWT.NONE).setText("窗口2");

// 设定每个窗口weight的比例值
sashForm.setWeights(new int[]{20, 40});

效果

样式

SWT.HORIZONTAL

请注意,在SashForm中,HORIZONTAL表示的是垂直划分


SWT.VERTICAL

请注意,在SashForm中,VERTICAL表示的是水平划分


SWT.BORDER

加粗边框


SWT.SMOOTH

平滑边框

设置窗口显示比例

sashForm.setWeights(new int[]{25, 50, 25}); 其中int\[\]数组的元素个数等于绑定sashForm面板的元素的个数。int\[\]数组中的数值表示每个组件的宽度比例

多层划分窗口

如果想要在已经分割的窗口上继续分割,可以在窗口上继续绑定SashForm

java 复制代码
public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setSize(500, 400);

    // 创建两列的sashForm
    SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
    sashForm.setLayout(new GridLayout(1, true));

    // 划分左侧区间, 创建两行的leftSashForm
    SashForm leftSashForm = new SashForm(sashForm, SWT.VERTICAL);
    leftSashForm.setLayout(new GridLayout(1, true));

    Composite leftUp = new Composite(leftSashForm, SWT.BORDER);
    leftUp.setLayout(new FillLayout());
    new Text(leftUp, SWT.NONE).setText("左上");

    Composite leftDown = new Composite(leftSashForm, SWT.BORDER);
    leftDown.setLayout(new FillLayout());
    new Text(leftDown, SWT.NONE).setText("左下");

    Composite right = new Composite(sashForm, SWT.BORDER);
    right.setLayout(new FillLayout());
    new Text(right, SWT.NONE).setText("右");

    shell.open();
    while (!shell.isDisposed()) {
        while (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    shell.dispose();
}

CBanner

CBanner将容器划分为三个部分,左侧,右侧,底栏

CBanner的创建方式如下

java 复制代码
CBanner cBanner = new CBanner(shell, SWT.BORDER);
cBanner.setLayout(new FillLayout());

// 创建3个面板
Composite c1 = new Composite(cBanner, SWT.NONE);
c1.setLayout(new FillLayout());
new Label(c1, SWT.NONE).setText("面板1");

Composite c2 = new Composite(cBanner, SWT.NONE);
c2.setLayout(new FillLayout());
new Label(c2, SWT.NONE).setText("面板2");

Composite c3 = new Composite(cBanner, SWT.NONE);
c3.setLayout(new FillLayout());
new Label(c3, SWT.NONE).setText("面板3");

// 设置控件
cBanner.setLeft(c1);
cBanner.setRight(c2);
cBanner.setBottom(c3);

效果

CBanner需要额外手动设置绑定位置。绑定为api为setLeft(Composite composite), setRight(Composite composite), setBottom(Composite composite)

相关推荐
QianhangQianping7 分钟前
撤销重做不是「存快照」:一个可视化编辑器的Operation 设计
java·前端·数据库·typescript·编辑器·前端架构·撤销重做
海绵宝宝转agent13 分钟前
LeetCodehot100题解
java·笔记·学习·算法·leetcode·深度优先
SunnyDays101114 分钟前
Java 操作 Word 脚注和尾注:添加、读取与删除
java·word
SunnyDays101115 分钟前
Java 为 Word 添加页码:隐藏封面页码、从指定页开始编号、奇偶页页码设置等
java·word·页码
开源推荐官19 分钟前
多门店 O2O 商城选型复盘:从开发视角对比主流开源系统
java·架构·开源·php
吴名氏.20 分钟前
Java转AI Agent教程(第二周)超时重试与错误分类
java·人工智能·python·分类·ai agent
从琳开始9891 小时前
从Socket到UDP回显服务器:Java网络编程完整指南
java·网络·网络协议·udp·java-ee
ShineWinsu1 小时前
对于Qt:QPushButton常见属性的解析
开发语言·c++·qt·api·gui·按钮·qpushbutton
西瓜拿铁好喝2 小时前
开源和闭源 AI 办公工具,分别适合谁
java·前端·数据库
学长毕设2 小时前
基于SpringBoot的校园礼服租赁系统的设计与实现
java·spring boot·后端