Child pages
  • MenuBar

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Divcache
Div
iddescription
HTML Table
id
classservoy sSummary
Colgroup Tag
Col
width80px
Col
Table Head (thead)
Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Method Summary
Table Row (tr)
Table Cell (td)
Menu
Table Cell (td)addMenu()
styleindexdisplay:none

DO NOT EDIT THE CONTENT OF THIS PAGE DIRECTLY (EXCEPT INSIDE THE DIV BELOW WITH ID=DESCRIPTION), UNLESS YOU KNOW WHAT YOU'RE DOING.
THE STRUCTURE OF THE CONTENT IS VITAL IN BEING ABLE TO AUTO UPDATE THE CONTENT THROUGH THE DOC GENERATOR.

true
refresh100d
showRefreshtrue
iddoc
titleRefresh page
showDatetrue
retryEnable
id

servoy sReturnTypes2100%height: 30px;2Supported ClientssWordListSmartClientsWordListWebClient

Table Cell (td)
Menu
Table Cell (td)addMenu(index)
servoy sSummary12%30%58%height: 30px;3Methods SummaryAdd a menu to the menubar. Table Row (tr) Table Row (tr)
Table Cell (td)
Menu
Table Cell (td)getMenu(index)
Add a menu to the menubar.Get the menu at the selected index (starting at 0). Table Row (tr)
Table Cell (td)
Number
Table Cell (td)getMenuCount()
Get the number of (top level) menu's. Table Row (tr)
Table Cell (td)
Number
Table Cell (td)getMenuIndexByText(name)
Retrieve the index of the item by text. Table Row (tr) Table Cell (td) Table Cell (td)removeAllMenus()
voidRemove all menus from the menubar. Table Row (tr) Table Cell (td) Table Cell (td)removeMenu(index)
voidRemove the menu(s) at the selected index/indices. Table Row (tr) Table Cell (td) Table Cell (td)reset()
voidReset the menubar to the default. Table Row (tr) Table Cell (td) Table Cell (td)setVisible(visible)
voidShow/hide the menu bar HTML Table

functionclass Colgroup Tag Colcolspanservoy sDetail2width100%

Col
Table Head (thead) Table Row (tr)styleheight:30px;
Table Head (th)
colspan2
Method Details
Table Body (tbody)
idaddMenu
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Menu
Span
stylefont-weight: bold;
addMenu
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Add a menu to the menubar.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Menu
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method addMenu only works in the smart client.

// when you don't define an index the menu will be added at the last
// positon of the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
// set the text of the menu
menu.text = "add menu";
// set the mnemonic key
menu.setMnemonic("a");
// add another menu at a specific position in the menubar
var another_menu = menubar.addMenu(2);
another_menu.text = "another menu";
another_menu.setMnemonic("t")
// REMARK: normally you would add menu items, checkboxes etc in the same method
// this example will show no menu items for now!
// IMPORTANT: Working with menu's on developer and client can differ
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idaddMenu-Number
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Menu
Span
stylefont-weight: bold;
addMenu
Span
(index)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Add a menu to the menubar.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{Number} index
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Menu
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method addMenu only works in the smart client.

// when you don't define an index the menu will be added at the last
// positon of the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
// set the text of the menu
menu.text = "add menu";
// set the mnemonic key
menu.setMnemonic("a");
// add another menu at a specific position in the menubar
var another_menu = menubar.addMenu(2);
another_menu.text = "another menu";
another_menu.setMnemonic("t")
// REMARK: normally you would add menu items, checkboxes etc in the same method
// this example will show no menu items for now!
// IMPORTANT: Working with menu's on developer and client can differ
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idgetMenu-Number
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Menu
Span
stylefont-weight: bold;
getMenu
Span
(index)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Get the menu at the selected index (starting at 0).
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{Number} index
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Menu
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method getMenu only works in the smart client.

var menubar = plugins.window.getMenuBar();
// get the menu at index 2
// indexes start at 0 (zero) so index 2 is in fact position 3
var menu = menubar.getMenu(2);
// set the text of the menu at the chose position
menu.text = "get menu";
// set the mnemonic key
menu.setMnemonic("g");
// disable the menu
menu.setEnabled(false);
// REMARK: we actually changed an original menu! As a result resetting the
// menubar will NOT reset the above changes. We need to reset the menu
// manually the following way:
// get the menu
//var menu = menubar.getMenu(2);
// reset the values to default
// notice we use an i18n message here the same way you would use it with
// standard Servoy methods and plugins
//menu.text = "i18n:servoy.menuitem.showAll";
//menu.setEnabled(true);
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idgetMenuCount
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Number
Span
stylefont-weight: bold;
getMenuCount
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Get the number of (top level) menu's.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method getMenuCount only works in the smart client.

// add a new menu before the last menu
var menubar = plugins.window.getMenuBar();
var count = menubar.getMenuCount();
var menu = menubar.addMenu(count-1);
menu.text = 'new menu';
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idgetMenuIndexByText-String
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Number
Span
stylefont-weight: bold;
getMenuIndexByText
Span
(name)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Retrieve the index of the item by text.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{String} name
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method getMenuIndexByText only works in the smart client.

var menubar = plugins.window.getMenuBar();
// find the index of the View menu
var idx = menubar.getMenuIndexByText("View");
// add a menu before the View menu
var menu = menubar.addMenu(idx);
menu.text = "new menu";
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idremoveAllMenus
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
void
Span
stylefont-weight: bold;
removeAllMenus
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Remove all menus from the menubar.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
void
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method removeAllMenus only works in the smart client.

// Potentially dangerous because all accelerator (short) keys
// will be deleted also (including the quit item)
var menubar = plugins.window.getMenuBar();
menubar.removeAllMenus();
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idremoveMenu-ObjectArray
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
void
Span
stylefont-weight: bold;
removeMenu
Span
(index)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Remove the menu(s) at the selected index/indices.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{Object[]} index -
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
void
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method removeMenu only works in the smart client.

var menubar = plugins.window.getMenuBar();
// To remove the last menu in the menubar we count the number of menu's in the menubar
// because the index starts at 0 we have to substract 1 from the counted menu's
// to actually remove the last menu from the menubar
var index = menubar.getMenuCount() - 1;
menubar.removeMenu(index);

// To remove the last 3 (three) menu's from the menubar we
// can do that by adding additional indexes to the method
// and delimit them with a comma.
index = menubar.getMenuCount() - 1;
menubar.removeMenu(index, index-1, index-2);

// For 'security' reasons it is best to ALWAYS remove the menu with the last index
// first to avoid index out of range issues and other issues
// EXAMPLE: when you first remove the menu at index 2 and then the menu at index 4
// you actually remove the menu at index 2 and index 5
// after removing the menu at index 2 all other menu's moved one index to the left
// so the menu at index 4 moved to index 3 and the menu at index 5 moved to index 4 etc.
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idreset
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
void
Span
stylefont-weight: bold;
reset
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Reset the menubar to the default.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
void
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method removeMenu only works in the smart client.

// When the menubar settings are solution specific it is advised to reset
// the bar to its default settings when closing the solution.
// Another reason is that when a client/developer is started first the
// plugin will save the current settings in memory.
// REMARK: Don't manipulate standard Servoy menuitems but remove
// them and create new ones! Due to the way menuitems are managed by java it is not
// possible to reset a menuitem anymore.
var menubar = plugins.window.getMenuBar();
// add a menu
var menu = menubar.addMenu();
menu.text = "new menu";
// reset the menubar, the newly added menu will dissapear
menubar.reset();
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idsetVisible-Boolean
Table Row (tr)
idname
Table Cell (td)
Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
void
Span
stylefont-weight: bold;
setVisible
Span
(visible)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Show/hide the menu bar
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{Boolean} visible
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
void
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
// Note: method setVisible only works in the smart client.

// hide the menu bar
var menubar = plugins.window.getMenuBar();
menubar.setVisible(false);
Table Row (tr)
classlastDetailRow
Table Cell (td) 2Methods DetailsaddMenuname

addMenu()

dessIndent
Add a menu to the menubar.
ret

Returns

sIndent
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow
addMenuname

addMenu(index)

dessIndent
Add a menu to the menubar.
prs

Parameters

sIndentindex ;
ret

Returns

sIndent
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow
getMenuname

getMenu(index)

dessIndent
Get the menu at the selected index (starting at 0).
prs

Parameters

sIndentindex ;
ret

Returns

sIndent
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow
getMenuCountname

getMenuCount()

dessIndent
Get the number of (top level) menu's.
ret

Returns

sIndent
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow
getMenuIndexByTextname

getMenuIndexByText(name)

dessIndent
Retrieve the index of the item by text.
prs

Parameters

sIndentname ;
ret

Returns

sIndent
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow
removeAllMenusname

removeAllMenus()

dessIndent
Remove all menus from the menubar.
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow
removeMenuname

removeMenu(index)

dessIndent
Remove the menu(s) at the selected index/indices.
prs

Parameters

sIndentindexarray of one or more indexes corresponding to menus to remove
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow
resetname

reset()

dessIndent
Reset the menubar to the default.
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow
setVisiblename

setVisible(visible)

dessIndent
Show/hide the menu bar
prs

Parameters

sIndentvisible ;
clients

Supported Clients

sIndentSmartClient,WebClient
sam

Sample

sIdentjavascript
lastDetailRow