ADC Home > Reference Library > Technical Q&As > Legacy Documents > Java >

Legacy Documentclose button

Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.

Current information on this Reference Library topic can be found here:

Submenus not Updating With Mac OS Screen MenuBar

Q: When I use the screenMenuBar property from Q&A 1003, submenus in my Swing application do not update if I add or remove JMenuItems to them.

A: This is a known problem with the current screenMenuBar implementation, and does not occur when using AWT, or using Swing without the screenMenuBar property set. The only current workaround is to remove and rebuild the submenu so the changed contents are forced to repaint in the Mac OS Screen MenuBar. Listing 1 shows how this might be done.

// Workaround:  Get all components of the subMenu and rebuild/replace it
// Call this code whenever adding or removing a Component of any kind
// (including JSeparators etc.) to a submenu
Component[] subMenuItems = subMenu.getMenuComponents();
subMenu = new JMenu("Open Recent");
for (int i=0; i < subMenuItems.length; i++) {

Listing 1. (Workaround) Removal of JMenuItems from submenus.

[Jul 12 2002]

Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.