java swt griddata_SWT中GridLayout 和GridData的使用

java swt griddata_SWT中GridLayout 和GridData的使用1.[代码][Java]代码packagecn.haibin.rcp.test.layer;importorg.eclipse.jface.viewers.TableViewer;importorg.eclipse.swt.SWT;importorg.eclipse.swt.layout.GridData;importorg.eclipse.swt.layout.GridLayout;i…

大家好,又见面了,我是你们的朋友全栈君。

1.[代码][Java]代码

package cn.haibin.rcp.test.layer;

import org.eclipse.jface.viewers.TableViewer;

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.GridData;

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.ExpandBar;

import org.eclipse.swt.widgets.ExpandItem;

import org.eclipse.swt.widgets.Group;

import org.eclipse.swt.widgets.Label;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.Table;

import org.eclipse.swt.widgets.TableColumn;

import org.eclipse.swt.widgets.Text;

import org.eclipse.swt.widgets.Tree;

import org.eclipse.swt.widgets.TreeItem;

/**

* GridLayout 布局测试示例

* @author cn.haibin

*

*/

public class TestGridLayout {

public static void main(String[] args) {

Display display = new Display();

Shell shell = new Shell(display);

shell.setText(“布局测试”);

shell.setSize(600, 400);

GridLayout layer = new GridLayout();

layer.numColumns = 2;

layer.makeColumnsEqualWidth = false;

layer.marginWidth = 5;

layer.marginHeight = 5;

layer.verticalSpacing = 0;

layer.horizontalSpacing = 1;

shell.setLayout(layer);

GridData treeGridData = new GridData(GridData.FILL_VERTICAL);

treeGridData.widthHint = 200;

Tree tree = new Tree(shell, SWT.SINGLE);

tree.setLayoutData(treeGridData);

TreeItem depart1 = new TreeItem(tree, SWT.NONE);

depart1.setText(“开发部门”);

{

TreeItem info1 = new TreeItem(depart1, SWT.NONE);

info1.setText(“软件工程师”);

TreeItem info2 = new TreeItem(depart1, SWT.NONE);

info2.setText(“测试工程师”);

}

TreeItem depart2 = new TreeItem(tree, SWT.NONE);

depart2.setText(“市场部”);

{

TreeItem info3 = new TreeItem(depart2, SWT.NONE);

info3.setText(“产品”);

TreeItem info4 = new TreeItem(depart2, SWT.NONE);

info4.setText(“运营”);

}

GridData expandBarGridData = new GridData(GridData.FILL_BOTH);

expandBarGridData.widthHint = 300;

ExpandBar expandBar = new ExpandBar(shell, SWT.V_SCROLL);

expandBar.setLayoutData(expandBarGridData);

{

Composite comp1 = new Composite(expandBar, SWT.NONE);

comp1.setLayout(new GridLayout(2, false));

Group group = new Group(comp1, SWT.NONE);

group.setText(“增加部门”);

Label lb_departCode = new Label(group, SWT.NONE);

lb_departCode.setBounds(10, 30, 100, 25);

lb_departCode.setText(“部门代码”);

Text txt_departCode = new Text(group, SWT.BORDER);

txt_departCode.setBounds(110, 30, 100, 25);

Label lb_departName = new Label(group, SWT.NONE);

lb_departName.setBounds(10, 60, 100, 25);

lb_departName.setText(“部门名称”);

Text txt_departName = new Text(group, SWT.BORDER);

txt_departName.setBounds(110, 60, 100, 25);

Button btn_ok = new Button(group, SWT.NONE);

btn_ok.setBounds(10, 90, 100, 25);

btn_ok.setText(“OK”);

Button btn_cancel = new Button(group, SWT.NONE);

btn_cancel.setBounds(110, 90, 100, 25);

btn_cancel.setText(“Cancel”);

new Label(comp1, SWT.NONE);

Group group1 = new Group(comp1, SWT.NONE);

group1.setText(“部门信息”);

final TableViewer tableViewer = new TableViewer(group1,

SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);

Table table = tableViewer.getTable();

table.setLinesVisible(true);

table.setHeaderVisible(true);

table.setBounds(10, 40, 400, 100);

final TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);

newColumnTableColumn.setWidth(120);

newColumnTableColumn.setText(“部门代码”);

final TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);

newColumnTableColumn_1.setWidth(120);

newColumnTableColumn_1.setText(“部门名称”);

Label lb_departCode1 = new Label(group1, SWT.NONE);

lb_departCode1.setBounds(10, 140, 100, 25);

lb_departCode1.setText(“部门代码”);

Button btn_departCode = new Button(group1, SWT.BORDER);

btn_departCode.setBounds(110, 140, 100, 25);

btn_departCode.setText(“查询”);

ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE);

item1.setText(“部门管理”);

item1.setHeight(400);// 设置Item的高度

item1.setControl(comp1);// setControl方法控制comp1的显现

}

{

Composite comp2 = new Composite(expandBar, SWT.NONE);

ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE);

item1.setText(“岗位管理”);

item1.setHeight(95);// 设置Item的高度

item1.setControl(comp2);// setControl方法控制comp1的显现

}

{

Composite comp3 = new Composite(expandBar, SWT.NONE);

comp3.setLayout(new GridLayout());

ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE);

item1.setText(“人员管理”);

item1.setHeight(50);// 设置Item的高度

item1.setControl(comp3);// setControl方法控制comp1的显现

}

shell.open();

while (!shell.isDisposed()) {

if (display.readAndDispatch()) {

display.sleep();

}

}

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/141354.html原文链接:https://javaforall.net

(0)
上一篇 2022年5月26日 上午7:40
下一篇 2022年5月26日 上午7:40


相关推荐

  • Python append 函数[通俗易懂]

    Python append 函数[通俗易懂]pythonappend描述append函数可以在列表的末尾添加新的对象。函数无返回值,但是会修改列表。append语法list.append(object)名称 说明 备注list 待添加元素的列表 object 将要给列表中添加的对象 不可省略的参数append举例1.给列表中添加整数、浮点数和字符串:test=[‘Python’,‘C’,‘Java’]test.append(5)test.append(23.6)test.append(‘HTML’)print(t

    2022年6月16日
    92
  • git的基本使用方法「建议收藏」

    git的基本使用方法「建议收藏」git的基本使用方法什么是git?git是目前世界上最先进的分布式版本控制系统。git与SVN的最主要区别?SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而工作的时候用的都是自己的电脑,所以开始工作之前需要从中央服务器那里获取最新的版本,然后开始工作,工作完后,需要把自己所做的工作推送到中央服务器。集中式版本控制系统必须要联网才能工作,如果在局域网中,有足够的宽带,运行速度…

    2022年6月29日
    26
  • 基于元学习的Agent智能体:概念、代码示例与应用场景

    基于元学习的Agent智能体:概念、代码示例与应用场景

    2026年3月15日
    2
  • Eclipse汉化教程(各版本通用)「建议收藏」

    Eclipse汉化教程(各版本通用)「建议收藏」Eclipse汉化教程1.确定Eclipse的版本方法一:打开eclipse,在启动画面中可以看到eclipse的版本名称(我的版是Photon),记住这个版本的名称;方法二:在Eclipse启动后,点击菜单栏中的**Help(帮助)>>AboutEclipse(关于EclipseIDE)**会弹出的AboutEclipse窗口,在这里也可以找到当前Ec

    2022年6月6日
    111
  • java中判断两个字符串是否相等「建议收藏」

    java中判断两个字符串是否相等「建议收藏」java中判断两个字符串是否相等

    2022年4月24日
    116
  • 12年3D建模师的感悟—写给还在迷茫中的朋友

    12年3D建模师的感悟—写给还在迷茫中的朋友不知不觉,从事3d行业已经12年了。今天想把这么久以来积攒的3D建模的学习经验彻底讲一下,希望能对你有所帮助。1.什么人适合学习3D建模?这个问题我曾经回答过,目前来看,闲来无事的大学生,目前做着和3D建模有关工作的人,比如雕刻家,和30岁以下想要转行的人都是适合的。至于其他人群,我是不推荐的,比如高中生之类的,或者年纪太大的。前者推荐上个大学,后者推荐找个轻松一点的工作。2.3D建模的职业规划怎么样?如果是大学生可能要好一点,有机会进大厂,如果是半路出家,可能游戏外包工作室就是归宿。当然也不

    2022年5月12日
    56

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号