| |
17. 13. 7. 添加图片标签 |
|
To get and set the image label for a label, you can use the following |
public Image getImage()
public void setImage(Image image)
|
|
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class LabelSetImage {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setLayout(new RowLayout());
Label label = new Label(shell, SWT.BORDER );
label.setText("text on the label");
label.setImage(new Image(display,"yourFile.gif"));
shell.open();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
}
}
|
|
|