我正在开发一个 Eclipse 插件,其中我想显示一个标签和一个进度条。但不幸的是我无法更改它们的大小。无论我在标签和进度条的 setBounds 属性中提到什么大小,都会给我坐标:矩形 { 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();
}
}
}
我无法继续。任何帮助将不胜感激。
最佳答案
您不能将布局与 setBounds 混合使用 - 布局将覆盖边界。如果删除setLayout
,边界将起作用。
但是,使用 setBounds
可能会在不同的屏幕上给您带来问题,因此您应该尝试使用不带 setBounds 的布局来完成此操作。
另请注意,Eclipse 向导、作业和其他东西已经提供了标准进度指示器。
关于java - eclipse 插件 setBounds 属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44384167/