在JFace ComboBoxCellEditor中剪切(隐藏)文本的一部分

时间:2018-04-10 17:49:27

标签: eclipse combobox swt jface

我在使用jface ComboBoxCellEditor时遇到问题,文本的一部分被剪切,如下图所示。

comboBox text cut

我正在使用这些插件,

org.eclipse.swt_3.106.1.v20170926-0519.jar org.eclipse.swt.win32.win32.x86_64_3.106.1.v20170926-0519.jar org.eclipse.jface_3.13.1.v20170810-0135.jar

此问题仅发生在Windows上,而不是UBUNTU上,因此它似乎是SWT或jface的错误。我提交了针对Eclipse SWT 533282的错误报告,但还没有得到回复。如果你们中的任何人都知道这个问题并且有解决方法,那对我来说非常有用。

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;

class CyTableComboBug extends Dialog
{
    int mComboIndex;  
    String[] mComboItems = new String[] { "Combo Item 1 long string",   
        "Combo Item 2" };   

    public CyTableComboBug(Shell parentShell)  
    {  
        super(parentShell);  
    }  

    @Override
    protected Control createDialogArea(final Composite parent)
    {
        final Composite container = 
            (Composite) super.createDialogArea(parent);

        TableViewer viewer = new TableViewer(container,  
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL |   
            SWT.FULL_SELECTION | SWT.BORDER);

        TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
        column.getColumn().setText("Column 1");
        column.setLabelProvider(new Column1LabelProvider());
        column.setEditingSupport(new Column1EditingSupport(viewer));

        viewer.setContentProvider(new ArrayContentProvider());
        viewer.setInput(new Integer[] { 0 });

        column.getColumn().pack();

        Table table = viewer.getTable();
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        return container;
    }

    private class Column1LabelProvider extends ColumnLabelProvider
    {
        @Override
        public String getText(Object element)
        {
            return mComboItems[mComboIndex];
        }
    }

    class Column1EditingSupport extends EditingSupport
    {
        protected ComboBoxCellEditor mEditor;

        public Column1EditingSupport(TableViewer viewer)
        {
            super(viewer);
            mEditor = new ComboBoxCellEditor(  
                viewer.getTable(), mComboItems,  
                SWT.READ_ONLY | SWT.BORDER);  

            mEditor.setActivationStyle(  
                ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION);
        }

        @Override
        protected boolean canEdit(final Object element)
        {
            return true;
        }

        @Override
        protected CellEditor getCellEditor(final Object element)
        {
            return mEditor;
        }

        @Override
        protected Object getValue(final Object element)
        {
            return mComboIndex;
        }

        @Override
        protected void setValue(final Object element, final Object value)
        {
            mComboIndex = (int) value;
        }
    }
}

0 个答案:

没有答案