Removing Menu Items from Window Tabs

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:


Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« August 2015
SunMonTueWedThuFriSat
      
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
     
Today