Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » How to change the alignment image/text in a ToolItem?(I would like create a tool item with a big image (top) and a simple label (center bottom))
How to change the alignment image/text in a ToolItem? [message #1068112] Fri, 12 July 2013 09:11 Go to next message
Francis Delsinnes is currently offline Francis DelsinnesFriend
Messages: 49
Registered: November 2011
Member
I don't understand why the following code does not work:

shell.setSize(240, 100);
ToolBar toolbar = new ToolBar(shell, SWT.FLAT);
toolbar.setSize(shell.getSize().x, 40);
toolbar.setLocation(0, 0);

//...

Image imageBtn2 = new Image(display, "btn2.bmp");
ToolItem btn2 = new ToolItem(toolbar, SWT.PUSH);
btn2.setImage(imageBtn2);
btn2.setText("Stop");

//...


With this code, I got a ToolItem with an Icon (btn2) and the label "Stop" on one line. (alignement: horizontal, left to right)


But I would like a ToolItem with an Icon on the top and the label to the center bottom... (alignement: vertical, top down) like that:
http://www.jmdoudoux.fr/java/dej/images/swt088.png

Today, I've two alternative solutions:
1. Make a Composite with an image and a label
2. Create an image with my icon and my text

But with the solution
#1, I cannot highlight my "button" (only the border of my composite by CSS theme)
#2, the font of my text and the text himself are fixed in the new image
Re: How to change the alignment image/text in a ToolItem? [message #1068175 is a reply to message #1068112] Fri, 12 July 2013 14:23 Go to previous messageGo to next message
Francis Delsinnes is currently offline Francis DelsinnesFriend
Messages: 49
Registered: November 2011
Member
Other problem with the alternative #1

Into the css style sheet:
you can set the cursor (style) on the image and the label but you cannot set a cursor on the parent composite...
Re: How to change the alignment image/text in a ToolItem? [message #1068178 is a reply to message #1068175] Fri, 12 July 2013 14:30 Go to previous messageGo to next message
Francis Delsinnes is currently offline Francis DelsinnesFriend
Messages: 49
Registered: November 2011
Member
Francis Delsinnes wrote on Fri, 12 July 2013 10:23
Other problem with the alternative #1

Into the css style sheet:
you can set the cursor (style) on the image and the label but you cannot set a cursor on the parent composite...


idea: manage the cursor by code...

  @Override public void setEnabled(boolean enabled) {

    getImageLabel().setEnabled(enabled);
    getTextLabel().setEnabled(enabled);
    super.setEnabled(enabled);

    if (enabled) {

      setCursor(new Cursor(getDisplay(), SWT.CURSOR_HAND));

    } else {

      setCursor(new Cursor(getDisplay(), SWT.CURSOR_ARROW));

    }

  }
Re: How to change the alignment image/text in a ToolItem? [message #1069101 is a reply to message #1068112] Mon, 15 July 2013 06:59 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Francis,
the desired by you behavior is controlled in SWT by SWT.RIGHT style flag
on the ToolBar:
-> SWT.RIGHT set - icon and text on the same line
-> SWT.RIGHT not set - icon on top, text below the icon, both centered
each other
In RAP, the SWT.RIGHT style flag is not supported. You can vote for this
enhancement.
237737: [ToolBar] SWT.RIGHT not supported
https://bugs.eclipse.org/bugs/show_bug.cgi?id=237737
Best,
Ivan

On 7/12/2013 12:11 PM, Francis Delsinnes wrote:
> I don't understand why the following code does not work:
>
>
> shell.setSize(240, 100);
> ToolBar toolbar = new ToolBar(shell, SWT.FLAT);
> toolbar.setSize(shell.getSize().x, 40);
> toolbar.setLocation(0, 0);
>
> //...
>
> Image imageBtn2 = new Image(display, "btn2.bmp");
> ToolItem btn2 = new ToolItem(toolbar, SWT.PUSH);
> btn2.setImage(imageBtn2);
> btn2.setText("Stop");
>
> //...
>
>
> With this code, I got a ToolItem with an Icon (btn2) and the label
> "Stop" on one line. (alignement: horizontal, left to right)
>
>
> But I would like a ToolItem with an Icon on the top and the label to
> the center bottom... (alignement: vertical, top down) like that:
>
>
> Today, I've two alternative solutions:
> 1. Make a Composite with an image and a label
> 2. Create an image with my icon and my text
>
> But with the solution #1, I cannot highlight my "button" (only the
> border of my composite by CSS theme)
> #2, the font of my text and the text himself are fixed in the new image

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: How to change the alignment image/text in a ToolItem? [message #1069126 is a reply to message #1068112] Mon, 15 July 2013 08:00 Go to previous message
Francis Delsinnes is currently offline Francis DelsinnesFriend
Messages: 49
Registered: November 2011
Member
Done.
Thanks for the feedback!
Previous Topic:Configuring jetty truststore unsuccessful
Next Topic:Mnemonic on top level menu item
Goto Forum:
  


Current Time: Wed Apr 24 22:45:01 GMT 2024

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

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

Back to the top