Hallo,
ich versuche seit einigen Stunden einen Fehler aus einer Test-Anwendung zu entfernen. Ich versuche mittels Control.print(gc) ein Label auf einem Composite zu zeichnen. Unter Windows XP/7 ist das Resultat wie erwartet. Linux macht hingegen Probleme. Dort wird der zu zeichnende Bereich mit nicht nachvollziehbarem Quatsch gefüllt. Kann mir jemand erklären, warum das so ist und was man tun kann um das Problem zu lösen?
ich versuche seit einigen Stunden einen Fehler aus einer Test-Anwendung zu entfernen. Ich versuche mittels Control.print(gc) ein Label auf einem Composite zu zeichnen. Unter Windows XP/7 ist das Resultat wie erwartet. Linux macht hingegen Probleme. Dort wird der zu zeichnende Bereich mit nicht nachvollziehbarem Quatsch gefüllt. Kann mir jemand erklären, warum das so ist und was man tun kann um das Problem zu lösen?
Java:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
public class SWTTest {
private Composite seComposite;
private Composite nwComposite;
private Composite neComposite;
private Composite swComposite;
private Label label;
private final Listener scrollBarListener = new Listener() {
public void handleEvent(Event event) {
FormData layoutData = null;
ScrollBar horizontalBar = SWTTest.this.seComposite.getHorizontalBar();
layoutData = (FormData) swComposite.getLayoutData();
layoutData.bottom = new FormAttachment(100, horizontalBar.isVisible() ? -horizontalBar.getSize().y : 0);
ScrollBar verticalBar = seComposite.getVerticalBar();
layoutData = (FormData) neComposite.getLayoutData();
layoutData.right = new FormAttachment(100, verticalBar.isVisible() ? -verticalBar.getSize().x: 0);
swComposite.getParent().layout();
}
};
public SWTTest(final Composite parent, int style) {
int headerHeight = 20;
int fixedWidth = 50;
FormData formData;
formData = new FormData();
formData.top = new FormAttachment(0, 0);
formData.right = new FormAttachment(0, fixedWidth);
formData.bottom = new FormAttachment(0, headerHeight);
formData.left = new FormAttachment(0, 0);
nwComposite = new Composite(parent, SWT.NONE);
nwComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
nwComposite.setLayoutData(formData);
formData = new FormData();
formData.top = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.bottom = new FormAttachment(0, headerHeight);
formData.left = new FormAttachment(0, fixedWidth);
neComposite = new Composite(parent, SWT.NONE);
neComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
neComposite.setLayoutData(formData);
formData = new FormData();
formData.top = new FormAttachment(0, headerHeight);
formData.right = new FormAttachment(0, fixedWidth);
formData.bottom = new FormAttachment(100, 0);
formData.left = new FormAttachment(0, 0);
swComposite = new Composite(parent, SWT.NONE);
swComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GREEN));
swComposite.setLayoutData(formData);
formData = new FormData();
formData.top = new FormAttachment(0, headerHeight);
formData.right = new FormAttachment(100, 0);
formData.bottom = new FormAttachment(100, 0);
formData.left = new FormAttachment(0, fixedWidth);
seComposite = new Composite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
seComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
seComposite.setLayoutData(formData);
seComposite.getHorizontalBar().addListener(SWT.Show, this.scrollBarListener);
seComposite.getHorizontalBar().addListener(SWT.Hide, this.scrollBarListener);
seComposite.getVerticalBar().addListener(SWT.Show, this.scrollBarListener);
seComposite.getVerticalBar().addListener(SWT.Hide, this.scrollBarListener);
seComposite.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
if (label == null || label.isDisposed())
return;
event.gc.setClipping(0, 0, 100, 20);
Transform transform = new Transform(event.gc.getDevice());
transform.translate(-5, -5);
event.gc.setTransform(transform);
// HIER TAUCHT DER FEHLER AUF
label.print(event.gc);
event.gc.dispose();
}
});
label = new Label(seComposite, SWT.NONE);
label.setText("TEST 123 TEST 456");
label.setBackground(label.getDisplay().getSystemColor(SWT.COLOR_CYAN));
label.setBounds(100, 100, 100, 20);
}
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setText("Shell");
shell.setLayout(new FormLayout());
new SWTTest(shell, SWT.NONE);
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}