Hiding Tabs for Undocked TopComponents

In our NetBeans Platform application, we have a TopComponent that needs to always be opened in an undocked and maximised state. When I manually undocked the window the first time though, I immediately noticed that the single tab that appears in the window just looks really silly.

So I set out to get the window to automatically undock as well as to remove that annoying tab.

In order to get the window to be opened as undocked, I needed to define a new separated mode to dock the window into. See section 3 of Geertjan’s Secrets of the NetBeans Window System post for more details about the mode. Note that the mode’s kind property needs to be editor for the whole thing to work.

I called my new mode floater, and the code that opens and maximises the window now looked like this:

[java]Mode floater = WindowManager.getDefault().findMode(“floater”);
TopComponent tc =
WindowManager.getDefault().findTopComponent(“test2TopComponent”);
floater.dockInto(tc);
tc.open();
JFrame root = (JFrame) SwingUtilities.getRoot(tc);
root.setExtendedState(root.getExtendedState() | Frame.MAXIMIZED_BOTH);[/java]

But the pesky tab was of course still there, so I needed more information. And in my search I came across another of Geertjan’s articles – Farewell to Space Consuming Weird Tabs. I did, however, not want to remove all the tabs from the whole application, just that particular one. So after creating the class test.NoTabsTabDisplayerUI as Geertjan describes, I had to find the right spot to set the UIManager property. And as it turns out, I just had to set the property before opening the window, and reset it to its previous value after. So the code finally is:

[java]Mode floater = WindowManager.getDefault().findMode(“floater”);
Object oldTabDisplayer = UIManager.get(“EditorTabDisplayerUI”);
UIManager.put(“EditorTabDisplayerUI”, “test.NoTabsTabDisplayerUI”);
TopComponent tc =
WindowManager.getDefault().findTopComponent(“test2TopComponent”);
floater.dockInto(tc);
tc.open();
JFrame root = (JFrame) SwingUtilities.getRoot(tc);
root.setExtendedState(root.getExtendedState() | Frame.MAXIMIZED_BOTH);
UIManager.put(“EditorTabDisplayerUI”, oldTabDisplayer);[/java]

Instructional designer, educational technologist and occasional lecturer who loves travel and photography

7 thoughts on “Hiding Tabs for Undocked TopComponents”

  1. I have a similar problem, but no easy way to solve it. I’ve created a “banner” mode that simply displays a TopComponent as a “banner” at the top of my application. I’ve done the .wsmode and .wsctref files so the banner is loaded when the program starts. I can’t find a way to get rid of the tabs since I don’t control the opening/docking of the banner TopComponent. I guess I would have to, in order to eliminate the tab.

    Reply
  2. Yeah, I’ve read through that post. They run into the same problem of not being able to set a single TopComponent to be tabless. I can’t use a toolbar; in fact, this problem arose when migrating FROM a toolbar. I needed to be able to “find” this component from other modules and using the TopComponent.Registry was the only method I could find. I don’t know how to “globally” look up components that aren’t TopComponents.

    Reply
    • For global access, my suggestion would be create a service (register it with the @ServiceProvider annotation). When your component is created, notify the service. And then request it from the service elsewhere in the application. That way the service acts as a global singleton. Let me know if you need more information about this approach.

      Reply
      • Yeah, there are other trade-offs with using a toolbar, namely sizing and taking up space reserved for, well, a toolbar. I prefer the “look” of having a new TopComponent in a “banner” mode to the toolbar where it was. I’m kind of familiar with service providers. I never thought of using one to get global access to an object/Component.

        Looking forward to seeing your new approach.

        Reply

Leave a Reply to Hermien Pellissier Cancel reply