首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SWT TableViewer页眉-高度

SWT TableViewer页眉-高度
EN

Stack Overflow用户
提问于 2011-04-27 22:59:47
回答 1查看 3.9K关注 0票数 0

我正在更改SWT Tableviewer的fontsize,但是表头的高度没有改变,因此标签被剪掉了。有没有办法解决这个问题?

(这是在Windows上)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-28 01:49:19

Table 隶属于SWT,另一个TableViewer 隶属于 JFace。因此,您是否需要针对TableViewerTable的解决方案尚不清楚。同样在你方没有任何代码片段的情况下,我选择为JFaceTableViewer演示它,尽管TableSWT的概念将保持不变。

设置字体之前的>>

设置字体后的>>

您可以看到标题高度的不同。

>>代码

代码语言:javascript
复制
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class TVHeaderTest 
{
    private class MyContentProvider implements IStructuredContentProvider {
        public Object[] getElements(Object inputElement) {
            return (MyModel[])inputElement;
        }
        public void dispose() {
        }
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    }

    public class MyModel {
        public int counter;
        public MyModel(int counter) {
            this.counter = counter;
        }
        public String toString() {
            return "Item " + this.counter;
        }
    }

    private static Display display;

    public TVHeaderTest(final Shell shell) 
    {
        final Table table = new Table (shell, SWT.H_SCROLL|SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION|SWT.CHECK);
        table.setLinesVisible (true);
        table.setHeaderVisible (true);

        final String[] titles = {"!", "Description", "Resource", "In Folder", "Location"};
        for (int i=0; i<titles.length; i++) {
            TableColumn column = new TableColumn (table, SWT.NONE);
            column.setText (titles [i]);
            column.setWidth(100);
        }

        final TableViewer v = new TableViewer(table);
        v.setLabelProvider(new LabelProvider());
        v.setContentProvider(new MyContentProvider());


        MyModel[] model = createModel();
        v.setInput(model);
        v.getTable().setLinesVisible(true);


        Button button = new Button(shell, SWT.PUSH);
        button.setText("Set Font");

        // FOCUS ON THIS PART - START
        button.addSelectionListener(new SelectionListener() 
        {
            public void widgetSelected(SelectionEvent e) 
            {
                FontDialog d = new FontDialog(shell);
                FontData data = d.open();
                table.setFont(new Font(display, data));
                for (int i = 0; i < titles.length; i++) {
                    table.getColumn(i).pack();
                }

            }
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        // FOCUS ON THIS PART - END
        shell.pack();
    }

    private MyModel[] createModel() {
        MyModel[] elements = new MyModel[10];
        for( int i = 0; i < 10; i++ ) {
            elements[i] = new MyModel(i);
        }
        return elements;
    }

    public static void main(String[] args) 
    {
        display = new Display ();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout());
        shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        new TVHeaderTest(shell);
        shell.open ();

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

        display.dispose ();

    }

}

检查// FOCUS ON THIS PART - START// FOCUS ON THIS PART - END注释之间的代码。

此外,您不能为设置标题图像执行此操作。请参阅Table Header Image Bug

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5806208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档