Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 656729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:44:45+00:00 2026-05-13T22:44:45+00:00

A bug has been filed and fixed (super quickly) in SWT: https://bugs.eclipse.org/bugs/show_bug.cgi?id=305294 Just to

  • 0

A bug has been filed and fixed (super quickly) in SWT:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=305294

Just to preface this, my goal here is to print the two images into a canvas so that I can animate the canvas sliding across the screen (think iPhone), sliding the controls themselves was too CPU intensive, so this was a good alternative until I tested it on Win7. I’m open to anything that will help me solve my original problem, it doesn’t have to be fixing the problem below.

Does anyone know how to get “Control.print(GC)” to work with Windows 7 Aero? I have code that works just fine in Windows XP and in Windows 7, when Aero is disabled, but the command:

control.print(GC) causes a non-top control to be effectively erased from the screen.

GC gc = new GC(image);
try {
    // As soon as this code is called, calling "layout" on the controls
    // causes them to disappear.
    control.print(gc);
} finally {
    gc.dispose();
}

I have stacked controls and would like to print the images from the current and next controls such that I can “slide” them off the screen. However, upon printing the non-top control, it is never redrawn again.

Here is some example code. (Interesting code bits are at the top and it will require pointing at SWT in order to work.)

Thanks for any and all help. As a work around, I’m thinking about swapping controls between prints to see if that helps, but I’d rather not.

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.GC;
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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class SWTImagePrintTest {
    private Composite stack;
    private StackLayout layout;
    private Label lblFlip;
    private Label lblFlop;
    private boolean flip = true;
    private Button buttonFlop;
    private Button buttonPrint;

    /**
     * Prints the control into an image
     * 
     * @param control
     */
    protected void print(Control control) {
        Image image = new Image(control.getDisplay(), control.getBounds());
        GC gc = new GC(image);
        try {
            // As soon as this code is called, calling "layout" on the controls
            // causes them to disappear.
            control.print(gc);
        } finally {
            gc.dispose();
        }
    }

    /**
     * Swaps the controls in the stack
     */
    private void flipFlop() {
        if (flip) {
            flip = false;
            layout.topControl = lblFlop;
            buttonFlop.setText("flop");
            stack.layout();
        } else {
            flip = true;
            layout.topControl = lblFlip;
            buttonFlop.setText("flip");
            stack.layout();
        }
    }

    private void createContents(Shell shell) {
        shell.setLayout(new GridLayout(2, true));
        stack = new Composite(shell, SWT.NONE);
        GridData gdStack = new GridData(GridData.FILL_BOTH);
        gdStack.horizontalSpan = 2;
        stack.setLayoutData(gdStack);
        layout = new StackLayout();
        stack.setLayout(layout);
        lblFlip = new Label(stack, SWT.BOLD);
        lblFlip.setBackground(Display.getCurrent().getSystemColor(
                SWT.COLOR_CYAN));
        lblFlip.setText("FlIp");
        lblFlop = new Label(stack, SWT.NONE);
        lblFlop.setBackground(Display.getCurrent().getSystemColor(
                SWT.COLOR_BLUE));
        lblFlop.setText("fLoP");
        layout.topControl = lblFlip;
        stack.layout();
        buttonFlop = new Button(shell, SWT.FLAT);
        buttonFlop.setText("Flip");
        GridData gdFlip = new GridData();
        gdFlip.horizontalAlignment = SWT.RIGHT;
        buttonFlop.setLayoutData(gdFlip);
        buttonFlop.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                flipFlop();
            }

        });
        buttonPrint = new Button(shell, SWT.FLAT);
        buttonPrint.setText("Print");
        GridData gdPrint = new GridData();
        gdPrint.horizontalAlignment = SWT.LEFT;
        buttonPrint.setLayoutData(gdPrint);
        buttonPrint.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                print(lblFlip);
                print(lblFlop);
            }
        });

    }


    /**
     * @param args
     */
    public static void main(String[] args) {
        Shell shell = new Shell();
        shell.setText("Slider Test");
        shell.setSize(new Point(800, 600));
        shell.setLayout(new GridLayout());
        SWTImagePrintTest tt = new SWTImagePrintTest();
        tt.createContents(shell);
        shell.open();
        Display display = Display.getDefault();
        while (shell.isDisposed() == false) {
            if (display.readAndDispatch() == false) {
                display.sleep();
            }
        }
        display.dispose();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:44:45+00:00Added an answer on May 13, 2026 at 10:44 pm

    This was the result of a bug:
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=305294

    It’s since been fixed. Hopefully a new packaged version of SWT will come out soon so we can officially use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 446k
  • Answers 446k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I applied all the css method, but not get proper… May 15, 2026 at 7:05 pm
  • Editorial Team
    Editorial Team added an answer You're initializing your MakeModelSpec "with a collection initializer". Collections such… May 15, 2026 at 7:05 pm
  • Editorial Team
    Editorial Team added an answer Qt is, among other things, a great framework for developing… May 15, 2026 at 7:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.