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

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

Problem

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.

Solution

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() {
    @Override
    public void run() {
        UIManager.put("EditorTabDisplayerUI", "todo.view.NoTabsTabDisplayerUI");
    }
 }); 

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

Advertisements
Categories: TopComponent
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: