gpt4 book ai didi

java - 向图像添加标签 SWT Java

转载 作者:行者123 更新时间:2023-12-01 19:05:44 25 4
gpt4 key购买 nike

我正在尝试在图像下添加标签。但按照以下方式执行不会显示任何标签。仅显示图像。

    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");

关于java - 向图像添加标签 SWT Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59557467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com