JTextComponent ed = org.netbeans.api.editor.EditorRegistry.lastFocusedComponent(); Document doc = ed.getDocument();