[SWT] Grafik repaint

Langrisser

Grünschnabel
Hallo zusammen,

ich möchte gerne ein Image in einer SWT-Dialogbox darstellen.
Nach einer Minimierung und anschließender Maximierung der DiagBox
verschwindet die zuvor sichtbare Grafik aber. Wie kann ich es anstellen,
dass die Grafik repainted wird?

Joe
 
Hallo!

Versuchs mal hiermit:

Code:
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.Rectangle;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class SWTDialogTest {

	public static void main(String[] args) {

		Display display = new Display();
		Shell shell = new Shell(display);

		shell.setText("Shell");
		shell.pack();
		shell.open();

		MyDialog dia = new SWTDialogTest().new MyDialog(shell);
		dia.setText(shell.getText());
		dia.open();

		while (!shell.isDisposed())
			if (!display.readAndDispatch())
				display.sleep();
	}

	class MyDialog extends Dialog {
		Object result;

		public MyDialog(Shell parent, int style) {
			super(parent, style);
		}
		public MyDialog(Shell parent) {
			this(parent, 0);
		}
		public Object open() {
			Shell parent = getParent();
			final Shell shell =
				new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
			shell.setText(getText());
			shell.pack();
			shell.open();

			final Image image =
				new Image(parent.getDisplay(), "c://energy.jpg");
			
			Rectangle rect = image.getBounds();
			shell.setSize(rect.width, rect.height);

			shell.addPaintListener(new PaintListener(){

				public void paintControl(PaintEvent e) {
					System.out.println("PaintEvent");
					e.gc.drawImage(image,0,0);
				}
			});
			
			Display display = parent.getDisplay();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
			image.dispose();
			
			return result;
		}
	}
}

Gruß Tom
 

Neue Beiträge

Zurück