【问题标题】:Eclipse-RCP view not coming on fullscreenEclipse-RCP 视图未全屏显示
【发布时间】:2015-04-01 14:28:34
【问题描述】:

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

这是我用来创建它的代码 sn-p

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的代码。

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 告诉这里是结果。这没有意义为什么当我进行所需的逻辑更改时尺寸变小了

【问题讨论】:

    标签: swt eclipse-rcp


    【解决方案1】:

    您弄错了 Composite 控件的父级,因此您最终会得到多个并排的复合材料。

    第一:

       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);
    

    您将parent 传递给CreatePartControl,因此您没有使用composite,但它会占用空间。

    第二:

    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,然后使用 parent 作为 Canvas 的父级,因此 ccanvas 并排。

    您还需要将绘图侦听器放在画布上,因为这是您想要绘制的内容。

    【讨论】:

    • 感谢您的解释,他们处于合乎逻辑的最佳状态,但在包括您的更改后,我得到了一些无法解释的东西。请参阅问题中的编辑。再次感谢
    • 您可能没有在各种控件上设置足够的布局和布局数据。用修改后的代码提出一个新问题。
    • 我通过使用填充布局解决了这个问题。但观点仍然正确......有什么想法吗?我应该为此添加一个新问题吗?
    • 是的,问一个新问题
    • 看看这个link我问了一个新问题。
    猜你喜欢
    • 2023-04-08
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多