RCP视图无法全屏显示

RCP视图无法全屏显示

本文介绍了Eclipse-RCP视图无法全屏显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RCP 3.x,并尝试在左侧创建一个我想要完整的布局。我尝试了很多组合,但似乎都没有用。这是屏幕截图。

I am using RCP 3.x and trying to create a layout which i want full and on the left hand side. I tried many combinations but none seem to work. Here is the screenshot.

这是我的代码段用于创建此

and here is the code snippet that i used to create this

public MonitorView(final Composite parent)
    {
        super(parent);
        setDisplayName(I18N("Visual Monitoring of iCommand"));
        setLayout(new GridLayout());
        final Composite composite=GUIToolkit.newComposite(parent, SWT.NONE, new GridData(SWT.TOP,SWT.LEFT,false,false,0,0));
        GridLayout layout=new GridLayout();
        composite.setLayout(layout);

        CreatePartControl(parent);

    }

    private void CreatePartControl(Composite parent)
    {
        // TODO Auto-generated method stub
        final Composite c =new Composite(parent,SWT.NONE);
        final Canvas canvas=new Canvas(parent,SWT.NONE);
        Color red = display.getSystemColor(SWT.COLOR_RED);
        canvas.setBackground(red);
        c.addPaintListener(new PaintListener() {
            @Override
            public void paintControl(PaintEvent event)
            {
                int offset_x=130;
                int offset_y=70;
                int j=0,i=0,n=3,x,y;

                DrawRoundedRectangle d= new DrawRoundedRectangle();
                //for loop for column 1.Placing elements column wise.

                for(i=0;i<n;i++)
                { x=0;y=offset_y*j;
                  d.drawrectangle(event, x, y, j);
                  j++;
                  x=0;y=offset_y*j;
                  d.drawrectangle(event, x, y, j);
                  j++;
                }

            j=0;int flag=6;
            //for loop for drawing column 2
                for(i=0;i<n;i++)
                {
                  x=offset_x; y=offset_y*j;
                  d.drawrectangle(event, x, y, flag);
                  j++;flag++;
                  x=offset_x;y=offset_y*j;
                  d.drawrectangle(event, x, y, flag);
                  flag++;
                  j++;
                }
            }
        });

    }



为什么从左开始的视图,以及为什么画布仅从右侧开始是红色的..为什么矩形的背景也不是红色。

以供参考。这是drawRoundedRectangle的代码。

For added reference. here is the code for drawRoundedRectangle.

void drawrectangle(PaintEvent event, int x,int y,int j)
    {
        event.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
        event.gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY));
        Font font = new Font(Display.getCurrent(),"Arial",font_size,SWT.BOLD | SWT.ITALIC);
        event.gc.setFont(font);
        event.gc.drawRoundRectangle(initial_pos_x+x,initial_pos_y+y,width_of_rect,height_of_rect,arc_width,arc_height);
        event.gc.fillRoundRectangle(initial_pos_x+adjust_pos_x+x,initial_pos_y+adjust_pos_y+y,width_of_rect+adjust_width_x,height_of_rect+adjust_height_y,arc_width,arc_height);
        event.gc.drawText(Services_name.get(j), text_x+x,text_y+y);
    }

:更改后@ greg449告诉这里结果。 当我进行必要的逻辑更改时,为什么尺寸变小

: After changes @greg449 told here is the result.It does not make sense why the size got smaller when i made the required logical changes

推荐答案

您正在获得Composite的父母

You are getting the parents of your Composite controls wrong so you are ending up with multiple composites side by side.

首先:

   final Composite composite=GUIToolkit.newComposite(parent, SWT.NONE, new GridData(SWT.TOP,SWT.LEFT,false,false,0,0));
    GridLayout layout=new GridLayout();
    composite.setLayout(layout);

    CreatePartControl(parent);

您正在将父级传递给 CreatePartControl ,因此您没有使用复合材料,但是会占用空间。

You are passing parent to CreatePartControl so you are not using composite but it will take up space.

第二个:

private void CreatePartControl(Composite parent)
{
    // TODO Auto-generated method stub
    final Composite c =new Composite(parent,SWT.NONE);
    final Canvas canvas=new Canvas(parent,SWT.NONE);

您创建复合 c ,然后使用父级作为画布的父级,因此 c canvas 并排放置。

You create composite c but then use parent as the parent for the Canvas so c and canvas are side by side.

您还需要画图侦听器在画布上,因为那是您想要的来画画。

You will also need the paint listener to be on the canvas since that is what you want to draw on.

这篇关于Eclipse-RCP视图无法全屏显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:44