Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Set Window Title for a NetBeans MultiViewElement

DZone's Guide to

Set Window Title for a NetBeans MultiViewElement

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. Brought to you in partnership with Lightbend.

When removing the default source editor for a DataObject, the editor window no longer displays the name of the file you are editing. To solve this, a few changes need to be made to the default editor of your custom file type (implementation of MultiViewElement):

Store the callback:

    private transient MultiViewElementCallback callback;

    @Override
    public void setMultiViewCallback(MultiViewElementCallback callback) {
        this.callback = callback;
    }

Create an update name method:

    public void updateName() {
        if (callback != null) {
            String name = getLookup().lookup(MyDataObject.class).getName();
            TopComponent tc = callback.getTopComponent();
            tc.setHtmlDisplayName(name);
            tc.setDisplayName(name);
            tc.setName(getName());
            tc.setToolTipText(getToolTipText());
        }
    } 

Make sure the name is updated when the component is showing:

    @Override
    public void componentShowing() {
        if (callback != null) {
            updateName();
        }
    }

 

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}