After a number of experiments, the following script has been developed. The only thing that is still not functioning properly is the color of the menu item for the sub popup menu. Aside from that, the script meets the requirements.
from javax.swing import JMenu, JMenuItem, JPopupMenu
from java.awt import Font
POPUPMENU_BACKGROUND=system.gui.color(220, 220, 220)
POPUPMENU_FOREGROUND=system.gui.color(0, 0, 0)
POPUPMENU_FONT=Font("Arial Narrow", Font.PLAIN, 20)
def dummy(event):
print 'dummy()'
def createJMenuItem(label, function, enabled, backgroundColor, foregroundColor, font):
menuItem=JMenuItem(label)
menuItem.addActionListener(function)
menuItem.setEnabled(enabled)
menuItem.setBackground(backgroundColor)
menuItem.setForeground(foregroundColor)
menuItem.setFont(font)
return menuItem
def createSubmenu(label):
subMenu=JMenu(label)
subMenu.setFont(POPUPMENU_FONT)
subMenu.setBackground(POPUPMENU_BACKGROUND)
subMenu.setForeground(POPUPMENU_FOREGROUND)
subMenu.add( createJMenuItem('Sub 1', dummy, False, POPUPMENU_BACKGROUND, POPUPMENU_FOREGROUND, POPUPMENU_FONT ) )
subMenu.add( createJMenuItem('Sub 2', dummy, True, POPUPMENU_BACKGROUND, POPUPMENU_FOREGROUND, POPUPMENU_FONT ) )
subMenu.add( createJMenuItem('Sub 3', dummy, True, POPUPMENU_BACKGROUND, POPUPMENU_FOREGROUND, POPUPMENU_FONT ) )
return subMenu
def createMainmenu():
mainMenu=system.gui.createPopupMenu([], [])
mainMenu.add( createJMenuItem('Main 1', dummy, True, POPUPMENU_BACKGROUND, POPUPMENU_FOREGROUND, POPUPMENU_FONT ) )
mainMenu.add( createJMenuItem('Main 2', dummy, True, POPUPMENU_BACKGROUND, POPUPMENU_FOREGROUND, POPUPMENU_FONT ) )
mainMenu.add( createJMenuItem('Main 3', dummy, True, POPUPMENU_BACKGROUND, POPUPMENU_FOREGROUND, POPUPMENU_FONT ) )
mainMenu.add( JPopupMenu.Separator() )
mainMenu.add( createSubmenu('Sub') )
return mainMenu
############################################################################
menu=createMainmenu()
menu.show(event, 0, 0)
print 'ok'