[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: Toolbar with JFace - is it a bug ?

Thanks a lot. It works fine.

There are 2 more minor questions however:
- how to get rid of the image at all ? this default small red square is
still there even I did not specify setImageDescriptor.
- is it possible to have this text on the right or on the left of the image
(now it is under the image)

Thanks again.
Aleksandr.

"Robin Barendregt" <robin.barendregt@xxxxxxxx> wrote in message
news:bad5gp$321$1@xxxxxxxxxxxxxxxx
> My guess is it's a bug. My (very) dirty patch is to do a setText() on the
> appropriate ToolItem's with the getText() of my ContributionItem's.
> Something like:
>
> private void setToolItemText() {
>     ToolItem[] items = ((ToolBar) getToolBarControl()).getItems();
>     items[0].setText(first);
>     for (int i = 1; i < items.length; i++) {
>         IContributionItem item = (IContributionItem) items[i].getData();
>        if (!(item.isGroupMarker() || item.isSeparator())) {
>             if (item instanceof ActionContributionItem)
>                 items[i].setText(((ActionContributionItem)
> item).getAction().getText());
>            else if (item instanceof SubContributionItem)
>                 items[i].setText(((ActionContributionItem)
> ((SubContributionItem) item).getInnerItem()).getAction().getText());
>         }
>     }
> }
>
> HTH,
> Robin.
>
>
> "Aleksandr" <aleksandrr@xxxxxxxxxxx> wrote in message
> news:babe6v$qmd$1@xxxxxxxxxxxxxxxx
> I tried some of the examples from http://eclipsewiki.swiki.net
> One of them:
>
> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
> public class test {
>  public static void main(String[] args) {
>   Shell shell = new Shell();
>   ToolBar bar = new ToolBar(shell, SWT.BORDER);
>
>   for (int i = 0; i < 8; i++) {
>    ToolItem item = new ToolItem(bar, SWT.PUSH);
>    item.setText("Item " + i);
>   }
>
>   bar.pack();
>   shell.open();
>   Display display = shell.getDisplay();
>
>   while (!shell.isDisposed()) {
>    if (!display.readAndDispatch()) {
>     display.sleep();
>    }
>   }
>   display.dispose();
>  }
> }
>
> works as it is suppsed to be.
> But another one:
>
> import org.eclipse.jface.window.*;
> import org.eclipse.jface.action.*;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.*;
> import org.eclipse.swt.widgets.*;
>
>
> public class test extends ApplicationWindow {
>
>  public test (Shell parentShell) {
>   super(parentShell);
>   addToolBar(SWT.FLAT | SWT.WRAP);
>   setBlockOnOpen(true);
>  }
>
>  public static void main(String[] args) {
>   Display display = new Display();
>   Shell aShell = new Shell(display);
>   ExSWT3 application = new test(aShell);
>
>   application.open();
>  }
>
>  protected Action createQuitAction() {
>   Action action = new Action() {
>    public String getText() {
>     return "Quit";
>    }
>
>    public String getToolTipText() {
>     return "Quit application ";
>    }
>
>    public void run() {
>     close();
>    }
>   };
>
>   action.setAccelerator('Q');
>   action.setChecked(false);
>   return action;
>  }
>
>
>  protected void configureShell(Shell shell) {
>   super.configureShell(shell);
>   shell.setText("Create tool bar");
>  }
>
>  protected Point getInitialSize() {
>   return new Point(600, 400);
>  }
>
>  protected Point getInitialLocation() {
>   return new Point(600, 400);
>  }
>
>  protected void handleShellCloseEvent() {
>   close();
>  }
>
>  protected ToolBarManager createToolBarManager(int style) {
>   ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.WRAP);
>
>   toolBarManager.add(createQuitAction());
>   return toolBarManager;
>  }
> }
>
>
> does not work correctly - there is no text in the button in the tool bar.
> It has only buttons with images (small red square which is default)
> Why ?
> Am I doing something wrong - but what ? I just downloaded the text,
> recompiled and executed. That's it.
> May be there is an error in this program (what is the error ? how to fix
> it?)
> or it is a bug in JFace/SWT ?
>
> Thank you,
>
> Aleksandr.
>
>