Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4672

Re: Help with SWT toolbars

From Jeff Higgins <jeff@invalid.invalid>
Newsgroups comp.lang.java.gui
Subject Re: Help with SWT toolbars
Date 2011-09-07 19:59 -0400
Organization A noiseless patient Spider
Message-ID <j490an$lv7$1@dont-email.me> (permalink)
References <103c3b49-21aa-4910-848a-ed1566228bf5@s2g2000vby.googlegroups.com>

Show all headers | View raw


On 09/07/2011 02:25 PM, Mike wrote:
> I am working my way through SWT: A Developer's Notebook by Tim Hatton
> and I'm having a problem with the toolbar lesson. Here is a part of
> the code:
>
>         final Image openIcon = new Image(d, "c:\\icons\\JavaCup.ico");
>         final Image saveIcon = new Image(d, "c:\\icons\\filesave.ico");
>
>         final Image cutIcon = new Image(d, "c:\\icons\\cut.png");
>         final Image copyIcon = new Image(d, "c:\\icons\\copy.png");
>         final Image pasteIcon = new Image(d, "c:\\icons\\paste.png");
>
>         // create and add the button for performing an open operation
>         final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH);
>         openToolItem.setImage(openIcon);
>         openToolItem.setText("Open");
>         openToolItem.setToolTipText("Open File");
>
>         //create and add the button for performing a save operation
>         final ToolItem saveToolItem = new ToolItem(bar, SWT.PUSH);
>         saveToolItem.setImage(saveIcon);
>         saveToolItem.setText("Save");
>         saveToolItem.setToolTipText("Save File");
>         ... more code follows...

Here is an excerpt from the book's downloadable code.

public class ToolbarShellExample {
   Display d;
   Shell s;
   ToolbarShellExample()    {
     d = new Display();
     s = new Shell(d);
     s.setSize(300,300);
     s.setImage(new Image(d, "c:\\icons\\JavaCup.ico"));
     s.setText("A Shell Toolbar Example");

     final ToolBar bar = new ToolBar(s,SWT.HORIZONTAL);
     bar.setSize(300,70);
     bar.setLocation(0,0);

     // create images for toolbar buttons
     final Image saveIcon = new Image(d, "c:\\icons\\save.jpg");
     final Image openIcon = new Image(d, "c:\\icons\\open.jpg");
     final Image cutIcon = new Image(d, "c:\\icons\\cut.jpg");
     final Image copyIcon = new Image(d, "c:\\icons\\copy.jpg");
     final Image pasteIcon = new Image(d, "c:\\icons\\paste.jpg");

     // create and add the button for performing an open operation
     final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH);
     openToolItem.setImage(openIcon);
     openToolItem.setText("Open");
     openToolItem.setToolTipText("Open File");

Maybe there is some weird interaction between
s.setImage(new Image(d, "c:\\icons\\JavaCup.ico"));
and your
final Image openIcon = new Image(d, "c:\\icons\\JavaCup.ico");
vs his
final Image openIcon = new Image(d, "c:\\icons\\open.jpg");

>
> With this code the program runs and the toolbar displays fine. However
> if I change the image for openIcon from JavaCup.ico to anything else,
> the toolbar does not display. The program however runs and there is no
> error written to console.
>
> With some experimentation, I have determined that the problem occurs
> whenever the first tool item added to the tool bar is not JavaCup.ico.
> If the icon of the first item is JavaCup.ico, the toolbar and all
> icons are displayed. Otherwise it is not.
>
> I am running on a Windows XP PC using J2SE-1.5. The SWT jar file is
> the one provided with Android. Could there be an issue here? I've gone
> through the web and found no mention of this.

Shrugs. Possible, have you tried another configuration?
The pdf excerpt of Hatton's Chapter 4 shows that he is using the Eclipse 
IDE. Are you? Are you using the Android SDK?

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Help with SWT toolbars Mike <mister270@gmail.com> - 2011-09-07 11:25 -0700
  Re: Help with SWT toolbars markspace <-@.> - 2011-09-07 13:27 -0700
    Re: Help with SWT toolbars Mike <mister270@gmail.com> - 2011-09-08 11:43 -0700
  Re: Help with SWT toolbars Jeff Higgins <jeff@invalid.invalid> - 2011-09-07 19:59 -0400
    Re: Help with SWT toolbars Mike <mister270@gmail.com> - 2011-09-08 11:55 -0700
      Re: Help with SWT toolbars Jeff Higgins <jeff@invalid.invalid> - 2011-09-08 15:31 -0400

csiph-web