Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to print contents of a scrolledComposite?
How to print contents of a scrolledComposite? [message #881553] Mon, 04 June 2012 20:27 Go to next message
abadamcd1 abadamcd1 is currently offline abadamcd1 abadamcd1Friend
Messages: 40
Registered: December 2011
Member
Does anyone know how I would print the contents of a scrolled composite?

Whenver I print onto a GC it will only copy the currently viewable area of the scrolled composite. What I want is to be able to copy the entire contents of the scrolled composite.

For instance, the code below makes a huge button, inside of a little window. Whenver I print the gc below, it only will output the small viewable area of the scrolled composite. Is it possible to print everything in the scrolled composite?


Shell shell = new Shell(getDisplay());
shell.setLayout(new FillLayout());
shell.setSize(200, 200);
shell.setLocation(20, 20);


ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL| SWT.V_SCROLL);
sc.setMinSize(availWidth, availHeight + 30);

Button b = new Button(sc, SWT.PUSH);
b.setText("Button");
b.setSize(availWidth, availHeight);
sc.setContent(b);

Image image = new Image(getDisplay(), availWidth, availHeight);
GC imageGC = new GC(image);
sc.print(imageGC);
Re: How to print contents of a scrolledComposite? [message #881933 is a reply to message #881553] Tue, 05 June 2012 14:13 Go to previous messageGo to next message
abadamcd1 abadamcd1 is currently offline abadamcd1 abadamcd1Friend
Messages: 40
Registered: December 2011
Member
I've found that behavior on Windows is different from behavior on Linux.

If I throw a big bunch of controls or pictures into a composite that I then put inside the scrolled composite, I can print the entire contents on the Windows platform. However, on GTK it will only print the viewable area of the scrolled composite.

I wonder if there is a workaround in SWT for this. My program needs to be cross-platform.
Re: How to print contents of a scrolledComposite? [message #882048 is a reply to message #881553] Tue, 05 June 2012 17:46 Go to previous message
abadamcd1 abadamcd1 is currently offline abadamcd1 abadamcd1Friend
Messages: 40
Registered: December 2011
Member
Here are examples of the problem. The first shot is the Windows 7 machine output, which is what I would expect from the code below. The second shot is the same code run on Ubuntu 12.04 Notice how the second image is the right size, but clips.

Windows
index.php/fa/10097/0/


Linux
index.php/fa/10096/0/

Code to generate this:
		Shell shell = new Shell(getDisplay());
        shell.setLayout(new FillLayout());
        shell.setSize(200, 200);
        shell.setLocation(20, 20);

        final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER  | SWT.V_SCROLL | SWT.H_SCROLL);
        sc.setLayout(new GridLayout(1,true));

        final Composite innerComposite = new Composite(sc, SWT.NONE);
        innerComposite.setSize(400, 400);
        innerComposite.setLayout(new GridLayout(1, true));
        innerComposite.setBackground(new Color(getDisplay(), 255, 0, 0));
        
        for(int i = 0; i < 10; i++)
        {
                Button b = new Button(innerComposite, SWT.PUSH);
                b.setText("Text");
                b.addSelectionListener(new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent e) 
                    {
                        Image image = new Image(getDisplay(), innerComposite.getBounds().width, innerComposite.getBounds().height);
                        ImageLoader loader = new ImageLoader();

                        GC gc = new GC(image);
                        innerComposite.print(gc);
                        
                        gc.dispose();

                        loader.data = new ImageData[]{image.getImageData()};
                        loader.save("c:/temp/out.png", SWT.IMAGE_PNG);
                    }
                });
        }

        sc.setMinSize(innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        sc.setContent(innerComposite);
        sc.setExpandHorizontal(true);
        sc.setExpandVertical(true);

		shell.open();

[Updated on: Tue, 05 June 2012 17:49]

Report message to a moderator

Previous Topic:swt table itemcount doubt
Next Topic:SWTError: No more handles in Eclipse 3.7.2 SDK on AIX 7.1
Goto Forum:
  


Current Time: Fri Apr 26 14:57:37 GMT 2024

Powered by FUDForum. Page generated in 0.04005 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top