PDA

View Full Version : Menu Create on Run Time



Achmad Amri
29 Nov 2011, 11:30 PM
Dear All,

I having trouble with EXT GWT Menu.

I want to create menu on run time, but nothing happens with the page although the method for create menu invoked.

Code


public class MainForm extends LayoutContainer {
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);

Button btnAdd = new Button("Add", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
createMenu();
}
});
add(btnAdd);
}

private void createMenu() {
// Start of Admin
Menu menu = new Menu();

MenuItem sub = new MenuItem("Company Info");
menu.add(sub);

Menu sub_sub = new Menu();

MenuItem miGeneral = new MenuItem("General", new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
WindowCompanyProfile.getWindow().show();
}
});
sub_sub.add(miGeneral);

MenuItem miLocations = new MenuItem("Locations");
sub_sub.add(miLocations);

MenuItem miCompanyStructure = new MenuItem("Company Structure");
sub_sub.add(miCompanyStructure);

MenuItem miCompanyProperty = new MenuItem("Company Property");
sub_sub.add(miCompanyProperty);

sub.setSubMenu(sub_sub);

MenuBar bar = new MenuBar();
bar.setBorders(true);
bar.setStyleAttribute("borderTop", "none");
bar.add(new MenuBarItem("Admin", menu));
// End of Admin

final ContentPanel panel = new ContentPanel();
panel.setHeaderVisible(false);
panel.setSize("100%", "100%");
panel.setTopComponent(bar);

add(panel, new FlowData(0));
}
}


Any suggestions?

Colin Alworth
30 Nov 2011, 11:20 AM
Note: you are posting in the Ext GWT 3 forum, whereas your code appears to be based on Ext GWT 2.

Without seeing how MainForm is created, used, it will be hard to say for sure, but it may be necessary to call layout() after calling add() at the end of the createMenu method.

Achmad Amri
1 Dec 2011, 11:03 PM
Sorry, I have been wrong to put this thread into the correct Category. This thread supposed to be in the Ext GWT 2.

The problem is solved, with adding layout() at the end of the createMenu method. Thanks Colin.

Code

public class MainForm extends LayoutContainer {
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);

Button btnAdd = new Button("Add", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
createMenu();
}
});
add(btnAdd);
}

private void createMenu() {
// Start of Admin
Menu menu = new Menu();

MenuItem sub = new MenuItem("Company Info");
menu.add(sub);

Menu sub_sub = new Menu();

MenuItem miGeneral = new MenuItem("General", new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
WindowCompanyProfile.getWindow().show();
}
});
sub_sub.add(miGeneral);

MenuItem miLocations = new MenuItem("Locations");
sub_sub.add(miLocations);

MenuItem miCompanyStructure = new MenuItem("Company Structure");
sub_sub.add(miCompanyStructure);

MenuItem miCompanyProperty = new MenuItem("Company Property");
sub_sub.add(miCompanyProperty);

sub.setSubMenu(sub_sub);

MenuBar bar = new MenuBar();
bar.setBorders(true);
bar.setStyleAttribute("borderTop", "none");
bar.add(new MenuBarItem("Admin", menu));
// End of Admin

final ContentPanel panel = new ContentPanel();
panel.setHeaderVisible(false);
panel.setSize("100%", "100%");
panel.setTopComponent(bar);

add(panel, new FlowData(0));
layout();
}
}