问题
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++;
}
}
});
}
Why is the view starting from left and why the canvas is red only from right side .. why the background of rectangles is also not red.
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);
}
[EDIT] : 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
回答1:
You are getting the parents of your Composite controls wrong so you are ending up with multiple composites side by side.
First:
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);
You are passing parent
to CreatePartControl
so you are not using composite
but it will take up space.
Second:
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);
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.
来源:https://stackoverflow.com/questions/29372028/eclipse-rcp-view-not-coming-on-fullscreen