【发布时间】: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