Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6955385

JTextComponent: inconsistent code for select operation

XMLWordPrintable

      JTextComponent: there is some inconsistency between following methods. In particular, second one checks for null whereas first do not.
      Moreover, I'd reuse the code like this:
          public void selectAll() {
              if (doc != null) {
                  select(0, getDocument().getLength());
              }
          }

      ---------
          public void select(int selectionStart, int selectionEnd) {
              // argument adjustment done by java.awt.TextComponent
              int docLength = getDocument().getLength();

              [...some bounds math...]
              setCaretPosition(selectionStart);
              moveCaretPosition(selectionEnd);
          }

          /**
           * Selects all the text in the <code>TextComponent</code>.
           * Does nothing on a <code>null</code> or empty document.
           */
          public void selectAll() {
              Document doc = getDocument();
              if (doc != null) {
                  setCaretPosition(0);
                  moveCaretPosition(doc.getLength());
              }
          }

            Unassigned Unassigned
            dav Andrei Dmitriev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: