Bug 330970

Summary: printing composite with children is not printing properly
Product: [Eclipse Project] Platform Reporter: Grant Gayed <grant_gayed>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: NEW --- QA Contact: Carolyn MacLeod <carolynmacleod4>
Severity: normal    
Priority: P3 CC: Brian_Young
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Grant Gayed CLA 2010-11-23 15:50:31 EST
snippet:

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(new GridLayout());
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Print Composite");

    for (int i = 0; i < 9; i++) {
        Composite child = new Composite(composite,SWT.BORDER);
        child.setLayoutData(new GridData(200, SWT.DEFAULT));
        child.setLayout(new GridLayout());
        new Label(child,SWT.NONE).setText("asdf: " + i);
    }

    button.addSelectionListener(new SelectionAdapter () {
        public void widgetSelected(SelectionEvent e) {
            PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
            PrinterData data = dialog.open();
            if (data != null) {
                Printer printer = new Printer(data);
                if (printer.startJob("Print Control")) {
                    if (printer.startPage()) {
                        GC gc = new GC(printer);
                        Point screenDPI = display.getDPI();
                        Point printerDPI = printer.getDPI();
                        float scaleFactor = (float)printerDPI.x / screenDPI.x;
                        Transform transform = new Transform(display, scaleFactor, 0, 0, scaleFactor, 0, 0);
                        transform.translate(200,200);
                        gc.setTransform(transform);
                        composite.print(gc);
                        transform.dispose();
                        gc.dispose();
                        printer.endPage();
                    }
                    printer.endJob();
                }
                printer.dispose();
            }
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
}
Comment 1 Eclipse Webmaster CLA 2019-09-06 15:32:40 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.