Do you mean the TextDocuments.java in the guide? It works fine if you want to go to the start, then jump some sentences and a few words and then write. But I'd like to write where the cursor (the blinking one) is, do you think it's possible? Or... Can anybody tell me where to look for it?
(Imagine OO embedded into an applet and when you click a button, some text is inserted where the cursor was) Joan -----Mensaje original----- De: Tobias Krais [mailto:[EMAIL PROTECTED] Enviado el: lunes, 13 de noviembre de 2006 13:23 Para: dev@api.openoffice.org Asunto: Re: [api-dev] Newbie inserting text where the cursor is (java) Hi Joan, > But now, how I manage to write something in that position? I use the method below to paste text on the position of a bookmark. You will also find the answer to you question in the developers guide. Greetings, Tobias -----%<----- /** * Sets the Cursor to a bookmark position and replaces text on this position. * If the bookmark contains more than at least one char, the text is * replaced. Otherwise the text is just inserted. * * @param bookmarkName Name of the Bookmark the cursor should jump to. * @param text The text that is going to be insertet on bookmark position */ public void replaceStringOnBookmark(String bookmarkName, String text) { try { // Get text document out the the general document XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xComponent); if (xTextDocument == null) { if (debug > 0) System.out.println("Document is not a Text Document." + " Aborting."); return; } // Get bookmark interface from document XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier) UnoRuntime.queryInterface(XBookmarksSupplier.class, xComponent); // Accessing the Bookmarks collection of the document XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks(); // Find the Bookmark specified in bookmarkName Object bookmark = null; try { bookmark = xNamedBookmarks.getByName(bookmarkName); } catch (Exception e) { return; } if (bookmark == null) { return; } // Query for XTextContext, the content of the Bookmark XTextContent xBookmarkContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, bookmark); // Get the anchor of the bookmark (its XTextRange) XTextRange xBookmarkRange = xBookmarkContent.getAnchor(); // Set string at bookmark position xBookmarkRange.setString(text); } catch (Exception e) { return; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail may contain confidential or privileged information. Any unauthorised copying, use or distribution of this information is strictly prohibited. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]