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

JTextComponent: inconsistent code for select operation

    Details

      Description

      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());
              }
          }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dav Andrei Dmitriev (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: