java - SWT How to print contents of a scrolledComposite? -


does know how print contents of scrolled composite?

whenver print onto gc copy viewable area of scrolled composite. want able copy entire contents of scrolled composite.

for instance, code below makes huge button, inside of little window. whenver print gc below, output small viewable area of scrolled composite. possible print in 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); 

note >>>

see @cryptdemon comments below. though solution known work on windows 7 , eclipse 3.7.x release.


yes possible. problem facing due way windows paint events generated (i assuming windows os because have !!) scrolling window.

at given moment (as per code) visible size of scrolled composite less actual size. when call print() on scrolled composite part of (which @ moment available/visible) gets printed. this:

border clarity

the solution create fixed composite inside scrolled composite , call print on that.

code:

import org.eclipse.swt.swt; import org.eclipse.swt.custom.scrolledcomposite; 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.imagedata; import org.eclipse.swt.graphics.imageloader; import org.eclipse.swt.layout.filllayout; import org.eclipse.swt.layout.gridlayout; import org.eclipse.swt.widgets.button; import org.eclipse.swt.widgets.composite; import org.eclipse.swt.widgets.display; import org.eclipse.swt.widgets.shell;  public class scrolled  {     public static void main(string[] args)     {         final display display = new display();          shell shell = new shell(display);         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));          for(int = 0; < 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(display, innercomposite.getbounds().width, innercomposite.getbounds().height);                         imageloader loader = new imageloader();                          gc gc = new gc(image);                         sc.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();         while (!shell.isdisposed()) {                 if (!display.readanddispatch())                         display.sleep();         }         display.dispose();     } } 

output:

enter image description here


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -