How to print contents of a scrolledComposite? [message #881553] |
Mon, 04 June 2012 16:27  |
Eclipse User |
|
|
|
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 #882048 is a reply to message #881553] |
Tue, 05 June 2012 13:46  |
Eclipse User |
|
|
|
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

Linux

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 13:49] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04157 seconds