为图像添加标签 SWT Java
Add a label to an image SWT Java
我正在尝试在图片下方添加标签。但是按照以下方式进行操作不会显示任何标签。只显示图片。
public void open() {
Display display = Display.getDefault();
createContents();
Label lblNewLabel = new Label(shell, SWT.NONE);
lblNewLabel.setBounds(40, 21, 217, 178);
lblNewLabel.setText("New Label");
Image i = new Image(display, "where the image is");
lblNewLabel.setImage(i);
CLabel cLabel = new CLabel(shell, SWT.ARROW_RIGHT);
cLabel.setImage(i);
cLabel.setText("SWT CLabel");
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
}
这样解决了:
Label lblNewLabel_1 = new Label(composite, SWT.BORDER);
GridData gd_lblNewLabel_1 = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
gd_lblNewLabel_1.widthHint = 193;
gd_lblNewLabel_1.heightHint = 193;
lblNewLabel_1.setLayoutData(gd_lblNewLabel_1);
Image image = new Image(display, "where the image is");
lblNewLabel_1.setImage(image);
lblNewLabel_1 = new Label(composite, SWT.BORDER);
lblNewLabel_1.setText("image label");
我正在尝试在图片下方添加标签。但是按照以下方式进行操作不会显示任何标签。只显示图片。
public void open() {
Display display = Display.getDefault();
createContents();
Label lblNewLabel = new Label(shell, SWT.NONE);
lblNewLabel.setBounds(40, 21, 217, 178);
lblNewLabel.setText("New Label");
Image i = new Image(display, "where the image is");
lblNewLabel.setImage(i);
CLabel cLabel = new CLabel(shell, SWT.ARROW_RIGHT);
cLabel.setImage(i);
cLabel.setText("SWT CLabel");
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
}
这样解决了:
Label lblNewLabel_1 = new Label(composite, SWT.BORDER);
GridData gd_lblNewLabel_1 = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
gd_lblNewLabel_1.widthHint = 193;
gd_lblNewLabel_1.heightHint = 193;
lblNewLabel_1.setLayoutData(gd_lblNewLabel_1);
Image image = new Image(display, "where the image is");
lblNewLabel_1.setImage(image);
lblNewLabel_1 = new Label(composite, SWT.BORDER);
lblNewLabel_1.setText("image label");