java - 如何删除Eclipse插件中的空格?

我是Eclipse插件开发的新手。

我使用Nebula开发了一些Eclipse插件,该插件提供了扩展视图组件,例如图形,表格等。

我想在视图中绘制三个组件(使用MeterFigure,SWT列表,XYGraph)。

但是,当我创建三个组件时,视图中有空白!

因此,我检查了我的代码,但找不到问题所在。

这是空白的捕获(请参见图和文本之间的空格)。
enter image description here

这是用于创建三个组件的代码。

@Override
    public void createPartControl(Composite parent) {
        ...
        GridLayout layout = new GridLayout(1, true);
        parent.setLayout(layout);
        parent.setLayoutData(new GridData(GridData.GRAB_VERTICAL));

        merterFigure = new merterFigureClass(parent, SWT.NONE);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        merterFigure.setLayoutData(gridData);

        list = new ListClass(parent, SWT.NONE);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        list.setLayoutData(gridData);
        list.initialize();

        graph = new GraphClass(parent, SWT.NONE);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        graph.setLayoutData(gridData);

        list.setGraph(graph);
    }


这是MeterFigureClass。

public class MeterFigureClass extends Canvas {
        private MeterFigure meterFigure;

        public MeterFigureClass(Composite parent, int style) {
            super(parent, style);

            LightweightSystem lws = new LightweightSystem(this);
            meterFigure = new MeterFigure();
            meterFigure.setBackgroundColor(XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
            meterFigure.setValueLabelVisibility(true);
            meterFigure.setRange(0, 100);
            meterFigure.setLoLevel(35);
            meterFigure.setLoloLevel(20);
            meterFigure.setHiLevel(85);
            meterFigure.setHihiLevel(70);
            meterFigure.setMajorTickMarkStepHint(80);

            lws.setContents(readabilityScore);
        }

        public void setValue(double value) {
            this.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    meterFigure.setValue(value);
                }
            });
        }
    }


这是ListClass。

public class ListClass extends Canvas {
        private org.eclipse.swt.widgets.List list;
        private List<Data> dataList;
        private GraphClass graph;

        public ListClass(Composite parent, int style) {
            super(parent, style);

            list = new org.eclipse.swt.widgets.List(parent, SWT.V_SCROLL | SWT.H_SCROLL);
            dataList = new ArrayList<Data>();

            ...

            GridData gridData = new GridData();
            gridData.horizontalAlignment = SWT.FILL;
            gridData.verticalAlignment = SWT.FILL;
            list.setLayoutData(gridData);

        }

        ....

        public void setGraph(GraphClass Graph) {
            this.Graph = Graph;
        }

        ....
    }


这是GraphClass。

ublic class MatrixGraph extends Canvas {
    private char count;
    private XYGraph matrixGraph;
    private LightweightSystem lws;

    public MatrixGraph(Composite parent, int style) {
        super(parent, style);
        addPaintListener(new PaintListener() {
            @Override
            public void paintControl(org.eclipse.swt.events.PaintEvent e) {
                MatrixGraph.this.paintControl(e);
            }
        });
    }

    public void paintControl(PaintEvent e) {
        if (count < 1)
            count++;
        else {
            lws = new LightweightSystem(this);

            matrixGraph = new XYGraph();

            setGraphProperties();

        }
    }

    ...
}

最佳答案

在您的GridData布局中,您指定:

    gridData.grabExcessVerticalSpace = true;


这告诉布局要抓住尽可能多的垂直空间,即使它可能只是空白。由于您是为多个控件指定的,因此多余的空间将在控件之间分配。

如果您不希望使用空格

gridData.grabExcessVerticalSpace = false;


或忽略它,因为它是默认设置。

也请尝试不使用FILL进行垂直对齐,TOP可能会更好:

gridData.verticalAlignment = SWT.TOP;