PDA

View Full Version : Render an image



zeroed
1 Dec 2011, 10:51 AM
Hi,

What is the best way to render an image in GXT?

I need it to be involved in layout system and to be active component.

Colin Alworth
1 Dec 2011, 4:41 PM
Can you be more specific? What kind of image, and how do you want it to take part in layout - or just to be resized? Is it enough to extend BoxComponent, and to draw an <img> tag with that, and override onResize to grow/shrink it?

What do you mean by 'active component'? If it extends Component (or some subclass), you will be able to add listeners to events, based on what events you sink to the dom.

zeroed
1 Dec 2011, 6:15 PM
Can you be more specific? What kind of image, and how do you want it to take part in layout - or just to be resized? Is it enough to extend BoxComponent, and to draw an <img> tag with that, and override onResize to grow/shrink it?

What do you mean by 'active component'? If it extends Component (or some subclass), you will be able to add listeners to events, based on what events you sink to the dom.

I want it basically to behave like a button. I want to be able to set an action listener to it on click. I want cursor to change to pointer when your mouse is hanging over an image. I want the parent to change it's size according to the image size.

Just as a usual component, that's all I need.

Colin Alworth
5 Dec 2011, 2:16 PM
Try subclassing BoxComponent, and going from there, starting with building onRender to draw as you want it to. It looks like setSize (invoked by layout) should be already set to resize the basic element drawn.

To get events call sinkEvents - take a look at how Button sets that up in its onRender method. Looking at Field and some of its subclasses should give you more ideas.