Example usage for javax.swing JMenu getItemCount

List of usage examples for javax.swing JMenu getItemCount

Introduction

In this page you can find the example usage for javax.swing JMenu getItemCount.

Prototype

@BeanProperty(bound = false)
public int getItemCount() 

Source Link

Document

Returns the number of items on the menu, including separators.

Usage

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ActionComponentManager.java

/**
 * Check and add menu item./*from www . ja  v  a  2  s . co  m*/
 *
 * @param menu the menu
 * @param menuItem the menu item
 * @param menuLocationIndex the menu location index
 */
private synchronized void checkAndAddMenuItem(JMenu menu, JMenuItem menuItem, int menuLocationIndex) {
    // check if menu has item count greater than menuLocationIndex
    int menuItemCount = menu.getItemCount();
    if (menuItemCount > menuLocationIndex) {
        menu.insert(menuItem, menuLocationIndex);
    } else {
        menu.insert(menuItem, menuItemCount);
    }

    //reset  quit menu item
    resetQuitMenuMenuItem();
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ActionComponentManager.java

/**
 * Reset quit menu menu item./*from   www  . j  av  a 2  s  .  co  m*/
 */
private synchronized void resetQuitMenuMenuItem() {
    // get file menu
    JMenu fileMenu = getMenuWithName("File");
    int itemCount = fileMenu.getItemCount();
    for (int i = 0; i < itemCount; i++) {
        JMenuItem item = fileMenu.getItem(i);
        if ("exitMenuItem".equals(item.getName())) {
            // reset item to last item
            fileMenu.insert(item, itemCount);
        }
    }
}