cornercorner
FeaturesPluginsDocs & SupportCommunityPartners

DevFaqGetOpenEditorWindows

How can I get a list of open editor windows?


Following applies to: 4.x, 5.x, 6.x


To obtain a reference to the currently selected editor:

Node[] arr = TopComponent.getRegistry().getCurrentNodes();
for (int i = 0; i < arr.length; i++) {
    EditorCookie ec = (EditorCookie) arr[I].getCookie(EditorCookie.class);
    if (ec != null) {
        JEditorPane[] panes = ec.getOpenedPanes();
        if (panes != null) {
            // USE panes
        }
    }
}

Following applies to: NetBeans 4.0, 4.1


To obtain references to all opened editors:

TopComponent[] comps = TopComponent.getRegistry().getOpened();
for (int i = 0; i < comps.length; i++) {
    Node[[ | ]] arr = comps[I].getActivatedNodes();
    for (int j = 0; j < arr.length; j++) {
        EditorCookie ec = (EditorCookie) arr[J].getCookie(EditorCookie.class);
        if (ec != null) {
            JEditorPane[] panes = ec.getOpenedPanes();
            if (panes != null) {
                // USE panes
            }
        }
    }
}

Following applies to: NetBeans 6.x


To obtain references to all opened editors-

Using Arrays
TopComponent[[ | ]] comps = TopComponent.getRegistry().getOpened().toArray(new TopComponent[0]);
for (int i = 0; i < comps.length; i++) {
    Node[[ | ]] arr = comps[I].getActivatedNodes();
    for (int j = 0; j < arr.length; j++) {
        EditorCookie ec = (EditorCookie) arr[J].getCookie(EditorCookie.class);
        if (ec != null) {
            JEditorPane[] panes = ec.getOpenedPanes();
            if (panes != null) {
                // USE panes
            }
        }
    }
}
Using Set<E>
Set<TopComponent> comps = TopComponent.getRegistry().getOpened();
for (TopComponent tc: comps) {
    Node[] arr = tc.getActivatedNodes();
    for (int j = 0; j < arr.length; j++) {
        EditorCookie ec = (EditorCookie) arr[J].getCookie(EditorCookie.class);
        if (ec != null) {
            JEditorPane[] panes = ec.getOpenedPanes();
            if (panes != null) {
                // USE panes
            }
        }
    }
}

Reference- Editor Windows Reactivated