Home » Eclipse Projects » Remote Application Platform (RAP) » How to add image and specify location?
|
Re: How to add image and specify location? [message #520929 is a reply to message #520923] |
Mon, 15 March 2010 19:56 |
|
Hi Josh,
your parent probably has a layout which overrides the label bounds. You
either need to define the label position using this layout, or discard
the parent's layout and use Control#setBounds().
Layouts in SWT are explained in this article:
http://www.eclipse.org/articles/article.php?file=Article-Und erstanding-Layouts/index.html
Hope this helps,
Ralf
Josh Hester wrote:
> Hi, I'm thinking this should be pretty simple, all I want to do is add
> an image and specify its location on the screen.
>
> This is what I'm trying to do:
>
>
> Image myImage = Activator.getImageDescriptor("image.png").createImage();
> Label image = new Label(parent,0);
> Rectangle rec = myImage.getBounds();
> image.setBounds(500,40,rec.width,rec.height);
> image.setImage(myImage);
>
>
> It finds the image fine and puts it up there, but I can't get it to put
> it where I'd like (or anywhere other than where it wants).
>
> Could someone please advise me on the best way to go about this please?
>
> Thanks,
>
> -Josh
|
|
|
Re: How to add image and specify location? [message #520930 is a reply to message #520923] |
Mon, 15 March 2010 20:07 |
Josh Hester Messages: 30 Registered: July 2009 |
Member |
|
|
I am using a layout above this, but even if try to set the position using this layoutdata, I still can't move the image anywhere. Not only that but the height of the image is way off.
Here is the method in its entirety. Is this not the correct way of doing this? What I'd like is simply a place to output text, the "question". In that same view I'd like an image in the center.
public void createPartControl(Composite parent) {
_parent = parent;
GridLayout gl = new GridLayout();
gl.verticalSpacing = 10;
parent.setLayout(gl);
question = new Label(parent, 0);
question.setText("ready to work");
question.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
question.setBounds(10, 10, 200, 15);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
question.setLayoutData(gridData);
Image myImage = Activator.getImageDescriptor("image.png").createImage();
Label image = new Label(parent,0);
Rectangle rec = myImage.getBounds();
image.setBounds(500,40,rec.width,rec.height);
image.setLayoutData(gridData);
image.setImage(myImage);
//parent.setBackgroundImage(myImage);
}
[Updated on: Mon, 15 March 2010 20:08] Report message to a moderator
|
|
|
Re: How to add image and specify location? [message #520933 is a reply to message #520930] |
Mon, 15 March 2010 20:19 |
|
Josh,
this code will not work. If you're using a layout, the #setBounds calls
won't have any effect. EITHER use a layout OR use absolute positioning.
Ralf
Josh Hester wrote:
> I am using a layout above this, but even if try to set the position
> using this layoutdata, I still can't move the image anywhere. Not only
> that but the height of the image is way off.
>
> Here is the method in its entirety.
>
> public void createPartControl(Composite parent) {
> _parent = parent;
> GridLayout gl = new GridLayout();
> gl.verticalSpacing = 10;
>
>
> parent.setLayout(gl);
> question = new Label(parent, 0);
> question.setText("ready to work");
>
> question.setBackground(parent.getDisplay().getSystemColor(SW T.COLOR_TITLE_BACKGROUND));
>
> question.setBounds(10, 10, 200, 15);
> GridData gridData = new GridData();
> gridData.horizontalAlignment = GridData.FILL;
> gridData.grabExcessHorizontalSpace = true;
> question.setLayoutData(gridData);
>
>
> Image myImage =
> Activator.getImageDescriptor("image.png").createImage();
> Label image = new Label(parent,0);
> Rectangle rec = myImage.getBounds();
> image.setBounds(500,40,rec.width,rec.height);
> image.setLayoutData(gridData);
> image.setImage(myImage);
>
>
> //parent.setBackgroundImage(myImage);
> }
>
|
|
| |
Re: How to add image and specify location? [message #522208 is a reply to message #522083] |
Sun, 21 March 2010 09:59 |
|
Josh Hester wrote:
> Ok, then say if I am using a layout, and I have a label inserted.
>
> Then later I want to add a text box to this layout, how can I remember
> the previous layout in order to place the text box under the original
> label?
You don't. If you're using a layout, the layout places your widgets. You
can attach layout data to the widgets to adjust their placement and
dimensions. You only add the textbox to the parent, that's it.
> Whenever I create the text box, it seems to create a new layout and put
> the text box over my old label.
No. "It" does not create a new layout. But you might need to call
parent.layout() after inserting new widgets in order to trigger a re-layout.
> Thanks for your help, I've read the article on layouts but it doesn't
> seem to address this situation.
Sorry for that. But I can't help much either without a sketch or a code
snippet.
Ralf
|
|
|
Goto Forum:
Current Time: Sun Nov 10 02:59:26 GMT 2024
Powered by FUDForum. Page generated in 0.04156 seconds
|