package de.tutorials;
import java.io.File;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class SWTImageGallery {
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("SWTChangeWidgetsExample");
shell.setLayout(new GridLayout(2, true));
File imageFolder = new File("E:/images");
File[] files = imageFolder.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
Label lbl = new Label(shell, SWT.BORDER);
String filePath = file.getAbsolutePath();
ImageData id = new ImageData(filePath);
lbl.setImage(new Image(display, id.scaledTo(180, 120)));
StringBuffer buffer = new StringBuffer("File: ");
buffer.append(filePath);
buffer.append("\n");
buffer.append("width: ");
buffer.append(id.width);
buffer.append("\n");
buffer.append("height: ");
buffer.append(id.height);
lbl.setToolTipText(buffer.toString());
}
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}