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

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

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();
        }
    }

 

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. 

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}