DevFaqSwitchingMenusByContext

(Difference between revisions)
(How can I change the contents of a menu according to the selected file in the editor?)
 
(6 intermediate revisions not shown)
Line 1: Line 1:
-
__NOTOC__
 
__NOTOC__
__NOTOC__
===How can I change the contents of a menu according to the selected file in the editor?===
===How can I change the contents of a menu according to the selected file in the editor?===
Line 6: Line 5:
* Return a special <tt>JMenuItem</tt> subclass that implements [http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/DynamicMenuContent.html DynamicMenuContent] from <tt>getMenuPresenter()</tt>
* Return a special <tt>JMenuItem</tt> subclass that implements [http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/DynamicMenuContent.html DynamicMenuContent] from <tt>getMenuPresenter()</tt>
* Implement [http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/DynamicMenuContent.html DynamicMenuContent] methods to return the desired menu content, using [http://bits.netbeans.org/dev/javadoc/org-openide-windows/org/openide/windows/TopComponent.Registry.html TopComponent.Registry] for finding the selected file in the editor.
* Implement [http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/DynamicMenuContent.html DynamicMenuContent] methods to return the desired menu content, using [http://bits.netbeans.org/dev/javadoc/org-openide-windows/org/openide/windows/TopComponent.Registry.html TopComponent.Registry] for finding the selected file in the editor.
 +
 +
https://bitbucket.org/jglick/dynamicmenudemo/ also does something similar.
===Can I hide or show a whole menu or toolbar?===
===Can I hide or show a whole menu or toolbar?===
Line 11: Line 12:
To hide a menu or toolbar you have to edit your <tt>layer.xml</tt> and append <tt>_hidden</tt> to the name of the desired menu or toolbar. You may also hide <tt>*.instance</tt> files.
To hide a menu or toolbar you have to edit your <tt>layer.xml</tt> and append <tt>_hidden</tt> to the name of the desired menu or toolbar. You may also hide <tt>*.instance</tt> files.
-
<pre>
+
<syntaxhighlight lang="xml" enclose="div" highlight="6">
<folder name="Menu">
<folder name="Menu">
     <!-- Hide View menu -->
     <!-- Hide View menu -->
Line 24: Line 25:
     <folder name="Edit_hidden"/>
     <folder name="Edit_hidden"/>
</folder>
</folder>
-
</pre>
+
</syntaxhighlight >
 +
 
 +
It's generally much easier to do this from the NetBeans IDE, [http://forums.netbeans.org/post-77476.html as described here].
-
It's generally much easier to do this from the NetBeans IDE, [http://openide.netbeans.org/servlets/ReadMsg?list=dev&msgNo=22010 as described here].
+
Note that to hide the Navigate menu one has to declare GoTo_hidden instead of Navigate_hidden (the menu was originally named GoTo, but was later renamed to Navigate by the means of Bundle.properties).

Current revision as of 00:20, 14 December 2011

How can I change the contents of a menu according to the selected file in the editor?

https://bitbucket.org/jglick/dynamicmenudemo/ also does something similar.

Can I hide or show a whole menu or toolbar?

To hide a menu or toolbar you have to edit your layer.xml and append _hidden to the name of the desired menu or toolbar. You may also hide *.instance files.

<folder name="Menu">
    <!-- Hide View menu -->
    <folder name="View_hidden"/>
    <folder name="SomeMenu">
        <!-- Hide a single menu item -->
        <file name="SomeAction.instance_hidden"/>
    </folder>
</folder>
<folder name="Toolbars">
    <!-- Hide Edit toolbar -->
    <folder name="Edit_hidden"/>
</folder>

It's generally much easier to do this from the NetBeans IDE, as described here.

Note that to hide the Navigate menu one has to declare GoTo_hidden instead of Navigate_hidden (the menu was originally named GoTo, but was later renamed to Navigate by the means of Bundle.properties).

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo