java - swt 表对单元格中的文本长度有限制吗?

标签 java swt jface

我使用JFace TableViewer和数据绑定(bind)来显示数据库表的数据,有些列的文本很长,我发现文本被剪掉了。如果我激活与该单元格关联的文本编辑器,我可以看到全文。

swt 表对单元格中的文本长度有限制吗?或者操作系统有这样的限制?(我使用的是 eclipse 3.6 和 windows 7 32 位)

/*******************************************************************************
 * Copyright (c) 2006 Tom Schindl and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tom Schindl - initial API and implementation
 *******************************************************************************/

package org.eclipse.jface.snippets.viewers;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * A simple TableViewer to demonstrate usage
 * 
 * @author Tom Schindl <tom.schindl@bestsolution.at>
 *
 */
public class Snippet001TableViewer {
    private class MyContentProvider implements IStructuredContentProvider {

        /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
         */
        public Object[] getElements(Object inputElement) {
            return (MyModel[])inputElement;
        }

        /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.IContentProvider#dispose()
         */
        public void dispose() {

        }

        /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
         */
        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 "very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text" + this.counter;**
        }
    }

    public Snippet001TableViewer(Shell shell) {
        final TableViewer v = new TableViewer(shell);
        v.setLabelProvider(new LabelProvider());
        v.setContentProvider(new MyContentProvider());
        MyModel[] model = createModel();
        v.setInput(model);
        v.getTable().setLinesVisible(true);
    }

    private MyModel[] createModel() {
        MyModel[] elements = new MyModel[10];

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

        return elements;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        Display display = new Display ();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        new Snippet001TableViewer(shell);
        shell.open ();

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

        display.dispose ();

    }

}

enter image description here

最佳答案

这是 Windows 错误/功能 ( see bugzilla for details ),这是证明(代码的 Linux 屏幕截图)

enter image description here

我也许可以通过自单元渲染来解决此错误/功能(请参阅 Custom Drawing Table and Tree Items 教程)。

关于java - swt 表对单元格中的文本长度有限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6621076/

相关文章:

java - 使用接口(interface)和实现实例化类

java - 如何使用 Token 作为参数实现 compareTo 方法

java - 如何使用 SWT 应用程序发送 XulRunner?

java - 如何在 SWT 中禁用组合框中的水平滚动条

java - SWT/JFace : remove widgets

java - 从 java 启动 .app 文件

java - 来自单独线程的 GUI

java - SWT - ScrolledComposite 内多行文本字段的 computingSize

java - Eclipse 插件 - 弹出菜单扩展

dialog - 如何确定 JFace 或 SWT 对话框当前处于打开状态?