如何在SWT表中设置可见行,包括单元格中的小部件? [英] How to set lines visible in SWT table, including widgets in cells?

查看:90
本文介绍了如何在SWT表中设置可见行,包括单元格中的小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含SWT的表,我使用TableEditor在表格单元格中包含了SWT小部件,例如Label,Text。但现在我的问题是,表格单元格的轮廓现在不可见。我想让所有列和行的边界可见。怎么做?设置 table.setLinesVisible(true)不成功!

I created a table with SWT and I included SWT widgets such as Label, Text in the table cells using TableEditor. But now my problem is, the outlines of the table cells are not visible now. I want to make visible all the borders of columns and rows. How to do it? Setting table.setLinesVisible(true) is not a success!

       Table table = new Table(detailArea, SWT.BORDER | SWT.MULTI);
       table.setLinesVisible(true);
       for (int i = 0; i < 4; i++) {
          TableColumn column = new TableColumn(table, SWT.NONE);
          column.setWidth(100);
       }

        TableItem x1= new TableItem(table, SWT.NONE);
        TableEditor editorw = new TableEditor(table);

        Label lblName =new Label(table, SWT.NONE);
        lblName.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        lblName.setText("Language");           
        editorw.grabHorizontal = true;
        editorw.setEditor(lblName, x1, 0);

        editorw = new TableEditor(table);
        Text txtLang = new Text(table, SWT.BORDER);
        editorw.grabHorizontal = true;
        editorw.setEditor(txtLang, x1, 1);                  

        editorw = new TableEditor(table);
        Label lblReference = new Label(table,
                SWT.NONE);
        lblReference.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        lblReference.setText("Value");
        editorw.grabHorizontal = true;
        editorw.setEditor(lblReference, x1, 2);

        editorw = new TableEditor(table);
        Text txtValue= new Text(table, SWT.BORDER);
        editorw.grabHorizontal = true;
        editorw.setEditor(txtValue, x1, 3);

        /////table row 2
        TableItem x2= new TableItem(table, SWT.NONE);
        editorw = new TableEditor(table);

        Label lblName2 =new Label(table, SWT.NONE);
        lblName2.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        lblName2.setText("Language");           
        editorw.grabHorizontal = true;
        editorw.setEditor(lblName2, x2, 0);

        editorw = new TableEditor(table);
        Text txtLang2 = new Text(table, SWT.BORDER);
        editorw.grabHorizontal = true;
        editorw.setEditor(txtLang2, x2, 1);

        editorw = new TableEditor(table);
        Label lblReference2 = new Label(table,
                  SWT.NONE);
        lblReference2.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        lblReference2.setText("Value");
        editorw.grabHorizontal = true;
        editorw.setEditor(lblReference2, x2, 2);

        editorw = new TableEditor(table);
        Text txtValue2= new Text(table, SWT.BORDER);
        editorw.grabHorizontal = true;
        editorw.setEditor(txtValue2, x2, 3);


        table.setLinesVisible(true);

以下是当前输出:

推荐答案

您可以将编辑器小部件(标签和文本)包装到 Composite 中。可以为复合提供边框和可以指定边距的布局:

You can wrap the editor widgets (label and text) into a Composite. The composite can be given a border and a layout that can specify a margin:

Composite composite = new Composite( table, SWT.BORDER );
GridLayout layout = new GridLayout();
composite.setLayout( layout );
Label label = new Label( composite, SWT.NONE );
GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true );
gridData.verticalIndent = 2;
gridData.horizontalIndent = 2;
label.setLayoutData( gridData );
editor.setEditor( composite, item, 0 );

另一种方法可能是所有者绘制表项特别是看到 EraseItem 事件可以用于绘制背景。但是我担心,因为你无法影响 TableEditor 的布局,所以编辑器小部件将隐藏所有者绘制的边框。

A different approach might be owner draw table items In particular see the EraseItem event that can be used to draw the background. However I am afraid that since you cannot influence the TableEditor's layout, the owner-drawn borders will be hidden by the editor widgets.

请注意,这种方法(无论是初始方法还是复合包装方法)对于几个hundret行都不能很好地扩展。对于每一行,将创建4或8个小部件。根据客户端计算机的性能,在创建多个hundret小部件并最终耗尽句柄时,它会变慢。

Note that this approach (neither your initial nor the composite-wrapped one) will not scale well for several hundret rows. For each row, 4 or 8 widgets will be created. Depending on the client computers performance it will slow down when creating several hundret widgets and eventually run out of handles.

这篇关于如何在SWT表中设置可见行,包括单元格中的小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆