Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Images on forms
Images on forms [message #454112] Mon, 18 April 2005 09:18 Go to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
Hello community,

I would like to present an image (JPG) on a form (org.eclipse.ui.forms).
My idea was to use an org.eclipse.swt.widgets.Canvas widget (was that a
reasonable idea?), which is a Composite. So I tried:

Composite sectionClient =
getToolkit().createComposite(getSection()); // getSection returns a
// formerly created Section instance
....
fCanvas = new Canvas(sectionClient, SWT.NONE);
getToolkit().adapt(fCanvas);

fCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
if (fImage != null && !fImage.isDisposed()) {
e.gc.drawImage(fImage, 0, 0);
}
}
});

GridLayout rightPartLayout = new GridLayout();
rightPartLayout.numColumns = 1;

fCanvas.setLayout(rightPartLayout);
getToolkit().paintBordersFor(fCanvas);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);

Should the call of adapt be sufficient for proper presentation?

The reasoning for my questions are due to the fact that in the
end my image is presented "clipped off" on the right and bottom side.
Please note that I have to assign the actual image during run-time
**after** creation of the composite. At this event I simply do:

public void setImage(Image img) {
fImage = img;
//fCanvas.layout(true, true); // Does actually not help
//fCanvas.redraw(); //Does not help either
}

Interestingly I could not get rid of the clipping problem by adding
SWT.V_SCROLL | SWT.H_SCROLL to the creation flags of the Canvas: The
bars are shown but any scrolling does not cause a corresponding
scrolling of the contained image.

Thank you for any ideas,

Daniel Krügler
Re: Images on forms [message #454116 is a reply to message #454112] Mon, 18 April 2005 12:24 Go to previous messageGo to next message
Robert Bacs is currently offline Robert BacsFriend
Messages: 165
Registered: July 2009
Senior Member
Hi,

To get rid of the clipping try to resize your canvas to your image width and
height. If you want to limit your canvas size and still able to display
larger image try to use ScrolledComposite.
Note: you will see a flickering in case of larger image, to get rid of this
flickering try to use SWT.NO_BACKGROUND style when creating the
canvas/scrolled composite.

Hope this helps,
Boby

"Daniel Kr
Re: Images on forms [message #454118 is a reply to message #454116] Mon, 18 April 2005 13:10 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
Hello Robert Bacs,

First, thank you for your answer!

Robert Bacs schrieb:
> Hi,
>
> To get rid of the clipping try to resize your canvas to your image width and
> height. If you want to limit your canvas size and still able to display
> larger image try to use ScrolledComposite.

Just to ensure that I don't misunderstand you: Do you mean

(a) Replace the Canvas by a ScrolledComposite (and thus directly put
draw the image on the composite) or
(b) Place the Canvas onto an additional ScrolledComposite?

> Note: you will see a flickering in case of larger image, to get rid of this
> flickering try to use SWT.NO_BACKGROUND style when creating the
> canvas/scrolled composite.

Thanks, that is a nice idea!

Greetings from Bremen,

Daniel Krügler
Re: Images on forms [message #454217 is a reply to message #454118] Tue, 19 April 2005 09:40 Go to previous message
Robert Bacs is currently offline Robert BacsFriend
Messages: 165
Registered: July 2009
Senior Member
Hi,

Place the canvas onto an additional ScrolledComposite.

Greetings from Timisoara (or Temeschburg/Temeswar),
Boby

"Daniel Kr
Previous Topic:Adding annotations to SourceViewer not visible
Next Topic:sorting org.eclipse.swt.widgets.List
Goto Forum:
  


Current Time: Fri Mar 05 20:49:27 GMT 2021

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

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

Back to the top