Archive for the ‘TopComponent’ Category

Recipe 12: How can I disable closing/undocking of a TopComponent?

March 4, 2014 Leave a comment


All top components contain a tab with a close (x) button. Once the user closes it, the only way to display it is via the Window menu or via Window | Reset Windows. However, if the Window menu has been deleted, then there is no other way to display the top component than restarting the application.


The close (x) button can be disabled by adding the following command(s) in the constructor of the top component:

putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
putClientProperty(TopComponent.PROP_UNDOCKING_DISABLED, Boolean.TRUE);

When creating a new TopComponent, you can disable closing it by checking the

  • Closing not allowed
  • Undocking not allowed

checkboxes in the first page of the New Window wizard.

As an aside, if you wish to completely get rid of the tab, then follow the instructions given here. In short add in the TopComponent‘s constructor:

SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        UIManager.put("EditorTabDisplayerUI", "todo.view.NoTabsTabDisplayerUI");

and add the new class NoTabsTabDisplayerUI as mentioned in the aforementioned blog.

Categories: TopComponent