eclipse 插件 setBounds 属性不起作用

eclipse plugin setBounds attribute not working

我正在开发一个 eclipse 插件,我想在其中显示标签和进度 bar.But 不幸的是,我无法更改它们的 size.Whatever 大小,我在标签和进度条的 setBounds 属性中提到,给我 coordinates:Rectangle {3, 3, 70, 15} 和矩形 {3, 21, 170, 17}

下面是我的处理程序代码:

private ProgressBar progressBar;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

        Display display = Display.getDefault();

        Shell p_shell = new Shell(display,SWT.DIALOG_TRIM);

        p_shell.setText("Translating..");

        p_shell.setLayout(new RowLayout(SWT.VERTICAL));

        p_shell.setSize(250, 70);

        Label label = new Label(p_shell, SWT.NONE);

        label.setBounds(10, 20, 180, 20);
        //LINE 101 gives Rectangle {3, 3, 70, 15}

        label.setText("Please wait ...");

        progressBar = new ProgressBar(p_shell, SWT.SMOOTH);

        //progressBar.setBounds(10, 50, 200, 20);
        //LINE 100 gives Rectangle {3, 21, 170, 17}

        progressBar.setBounds(new Rectangle(5, 30, 150, 10));
        //LINE 100 gives Rectangle {3, 21, 170, 17}         

        progressBar.setMinimum(30);

        progressBar.setMaximum(100);

        p_shell.open();

        System.out.println("progress bar  ==> " + progressBar.getBounds());//LINE 100

        System.out.println("label ==> " + label.getBounds());//LINE 101


        while(!p_shell.isDisposed()){

            if(!display.readAndDispatch()){
                display.sleep();
            }
        }
        }

我无法继续further.Any将不胜感激。

您不能将布局与 setBounds 混合使用 - 布局将覆盖边界。如果您删除 setLayout 边界将起作用。

然而,使用 setBounds 可能会给您在不同屏幕上带来问题,因此您应该尝试使用没有 setBounds 的布局来完成这项工作。

另请注意,Eclipse 向导、Jobs 和其他东西已经提供了标准的进度指示器。