/**
  * Sets the text of this AutoCompleteDocument to the given text.
  *
  * @param text the text that will be set for this document
  */
 private void setText(String text) {
   try {
     // remove all text and insert the completed string
     super.remove(0, getLength());
     super.insertString(0, text, null);
   } catch (BadLocationException e) {
     throw new RuntimeException(e.toString());
   }
 }
Ejemplo n.º 2
0
 /**
  * Scrolls the help browser to the element with id <code>id</code>
  *
  * @param id the id
  * @return true, if an element with this id was found and scrolling was successful; false,
  *     otherwise
  */
 protected boolean scrollToElementWithId(String id) {
   Document d = help.getDocument();
   if (d instanceof HTMLDocument) {
     HTMLDocument doc = (HTMLDocument) d;
     Element element = doc.getElement(id);
     try {
       Rectangle r = help.modelToView(element.getStartOffset());
       if (r != null) {
         Rectangle vis = help.getVisibleRect();
         r.height = vis.height;
         help.scrollRectToVisible(r);
         return true;
       }
     } catch (BadLocationException e) {
       Main.warn(tr("Bad location in HTML document. Exception was: {0}", e.toString()));
       e.printStackTrace();
     }
   }
   return false;
 }