本文主要是介绍SWT/Jface 图片自动缩放的例子,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原创的例子 图片是做到label上了 其实控件的原理是通的 大家想放哪就放哪 哈哈
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
* @Title: ImageTest.java
* @Description: TODO
* @author zouxs
* @date 2012-9-30
*/
public class ImageTest {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(600,300);
shell.setLayout(new GridLayout());
final Label label = new Label(shell, SWT.BORDER);
label.setLayoutData(new GridData(GridData.FILL_BOTH));
final Image image = new Image(display, "icons/test.jpg");
label.setImage(image);
label.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Point size = label.getSize();
Point p = label.getLocation();
e.gc.drawImage(image, 0, 0, 512, 78, p.x, p.y, size.x, size.y);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
这篇关于SWT/Jface 图片自动缩放的例子的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!