如何删除Eclipse插件中的空白区域?

时间:2017-02-21 08:09:23

标签: java eclipse eclipse-plugin

我是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();

        }
    }

    ...
}

1 个答案:

答案 0 :(得分:2)

在您指定的GridData布局中:

    gridData.grabExcessVerticalSpace = true;

这告诉布局尽可能多地占用垂直空间,即使它可能只是空白。由于您为多个控件指定了此项,因此在控件之间划分了额外的空间。

如果您不想使用空格

gridData.grabExcessVerticalSpace = false;

或者只是省略它,因为它是默认值。

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

gridData.verticalAlignment = SWT.TOP;