Greetings folks,

I have a nice solution in order to create a MenuBar with images/icons
that does not used the MenuBar.MenuBarImages.

1) I'm using a standard ImageBundle, for instance MyImageBundle which
extends ImageBundle interface with a folder that contains my images.

import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.ImageBundle;

public interface MyImageBundleInterface extends ImageBundle {

    // Abstract method that gives access to home.png
    public AbstractImagePrototype home();

    //...

    // Abstract method that gives access to add.png
    public AbstractImagePrototype add();

    // Abstract method that gives access to printer.png
    public AbstractImagePrototype printer();

}

2) In the class which build my menu bar I put a private variable and
    a public getter to my images bundle

    // Image Bundle
    private MyImageBundleInterface myImageBundle =
            (MyImageBundleInterface ) GWT.create
(MyImageBundleInterface .class);

    public MyImageBundleInterface  getMyImageBundle() {
        return monImageBundle;
    }


3) Within the class that creates the menu bar I put a method
   to create MenuItem with image

public MenuItem createMenuItem(String menuLabel,
AbstractImagePrototype menuImage) {
    Command nullCommand = null;
    MenuItem menuItem = new MenuItem(menuImage.getHTML() + " "+
menuLabel, true, nullCommand);
    return menuItem;
}

4) At the creation of the menu item

private MenuItem printMenuItem;

printMenuItem = createMenuItem("Print", getMonImageBundle().printer
());

5) In the case of a menu with sub-menu...

private MenuBar menubar;
private MenuBar addMenuBar;

addMenuBar = new MenuBar(true);
addMenuBar.setAutoOpen(true);
...

menuBar.addItem( getMyImageBundle().add().getHTML() + " " +
                 "Add",
                  true,
                  addMenuBar);

I hope this post could help someone...

Claude
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to