blob: f91bd9577118bf05deb3f295683b933b5b4a6e94 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= DevFaqUsingSubmenus
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqUsingSubmenus
:description: Apache NetBeans wiki DevFaqUsingSubmenus
:toc: left
:toc-title:
:syntax: true
=== Can I add submenus to context or main menus, instead of single menu items?
Yes, any place where the APIs expect to have an item
installed into a context or main menu, you can provide a submenu
instead.
Provide a dummy `Action` (it can be a do-nothing subclass of `javax.swing.AbstractAction`), or in some cases the class need not even be an `Action` at all. For context menus, implement the interface `link:http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/actions/Presenter.Popup.html[Presenter.Popup]` on your `Action`, and have it return a `JMenu` from `getPopupPresenter()`.
Similarly, you can implement other subinterfaces of `link:http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/actions/Presenter.html[Presenter]` to provide a different component to display in toolbars or the main menu.
*Note about using alternate components in the main menu:* If you want your action to work properly on Mac OS, you probably don't want to return anything other than a `JMenu` or `JMenuItem` from `getMenuPresenter()` if you implement link:http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/actions/Presenter.Menu.html[Presenter.Menu]. In general, Swing allows you to treat menu popups as generic Swing containers you can put what you like into. This is not true at all of the Mac OS screen menu bar - it expects normal menu items, and will not handle unusual contents for menus.
If you just return a `JMenu` from `getPopupPresenter` or `getMenuPresenter` it will always be displayed, though you can conditionally disable it. If you wish to sometimes hide (not just disable) the submenu, make it implement link:http://www.netbeans.org/download/dev/javadoc/org-openide-awt/org/openide/awt/DynamicMenuContent.html[DynamicMenuContent] and you can make the submenu appear or disappear whenever you like (or even provide more than one menu item / submenu).
=== Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from link:http://wiki.netbeans.org/DevFaqUsingSubmenus[http://wiki.netbeans.org/DevFaqUsingSubmenus] ,
that was last modified by NetBeans user Admin
on 2009-11-06T16:04:48Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.