Removing Menu Items from Window Tabs

Posted by Geertjan on Oracle Blogs See other posts from Oracle Blogs or by Geertjan
Published on Sun, 17 Aug 2014 07:00:00 +0000 Indexed on 2014/08/18 22:27 UTC
Read the original article Hit count: 309

Filed under:

So you're working on your NetBeans Platform application and you notice that when you right-click on tabs in the predefined windows, e.g., the Projects window, you see a long list of popup menus.

For whatever the reason is, you decide you don't want those popup menus. You right-click the application and go to the Branding dialog. There you uncheck the checkboxes that are unchecked below:

As you can see above, you've removed three features, all of them related to closing the windows in your application. Therefore, "Close" and "Close Group" are now gone from the list of popup menus:

But that's not enough. You also don't want the popup menus that relate to maximizing and minimizing the predefined windows, so you uncheck those checkboxes that relate to that:


And, hey, now they're gone too:


Next, you decide to remove the feature for floating, i.e., undocking the windows from the main window:

And now they're gone too:

However, even when you uncheck all the remaining checkboxes, as shown here...

You're still left with those last few pesky popup menu items that just will not go away no matter what you do:

The reason for the above? Those actions are hardcoded into the action list, which is a bug. Until it is fixed, here's a handy workaround:

  1. Set an implementation dependency on "Core - Windows" (core.window). That is, set a dependency and then specify that it is an implementation dependency, i.e., that you'll be using an internal class, not one of the official APIs.

  2. In one of your existing modules, or in a new one, make sure you have (in addition to the above) a dependency on Lookup API and Window System API.

  3. And then, add the class below to the module:
    import javax.swing.Action;
    import org.netbeans.core.windows.actions.ActionsFactory;
    import org.openide.util.lookup.ServiceProvider;
    import org.openide.windows.Mode;
    import org.openide.windows.TopComponent;
    
    @ServiceProvider(service = ActionsFactory.class)
    public class EmptyActionsFactory extends ActionsFactory {
    
        @Override
        public Action[] createPopupActions(TopComponent tc, Action[] actions) {
            return new Action[]{};
        }
    
        @Override
        public Action[] createPopupActions(Mode mode, Action[] actions) {
            return new Action[]{};
        }
        
    }

Hurray. Farewell to superfluous popup menu items on your window tabs. In the screenshot below, the tab of the Projects window is being right-clicked and no popup menu items are shown, which is true for all the other windows, those that are predefined as well as those that you add afterwards:


© Oracle Blogs or respective owner

Related posts about /NetBeans IDE