Java Code Examples for java.awt.peer.TextComponentPeer#select()

The following examples show how to use java.awt.peer.TextComponentPeer#select() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextComponent.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Selects all the text in this text component.
 * @see        java.awt.TextComponent#select
 */
public synchronized void selectAll() {
    this.selectionStart = 0;
    this.selectionEnd = getText().length();

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 2
Source File: TextComponent.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Selects all the text in this text component.
 * @see        java.awt.TextComponent#select
 */
public synchronized void selectAll() {
    this.selectionStart = 0;
    this.selectionEnd = getText().length();

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 3
Source File: TextComponent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Selects all the text in this text component.
 * @see        java.awt.TextComponent#select
 */
public synchronized void selectAll() {
    this.selectionStart = 0;
    this.selectionEnd = getText().length();

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 4
Source File: TextComponent.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Selects all the text in this text component.
 * @see        java.awt.TextComponent#select
 */
public synchronized void selectAll() {
    this.selectionStart = 0;
    this.selectionEnd = getText().length();

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 5
Source File: TextComponent.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Selects all the text in this text component.
 * @see        java.awt.TextComponent#select
 */
public synchronized void selectAll() {
    this.selectionStart = 0;
    this.selectionEnd = getText().length();

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 6
Source File: TextComponent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Selects all the text in this text component.
 * @see        java.awt.TextComponent#select
 */
public synchronized void selectAll() {
    this.selectionStart = 0;
    this.selectionEnd = getText().length();

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 7
Source File: TextComponent.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Selects all the text in this text component.
 * @see        java.awt.TextComponent#select
 */
public synchronized void selectAll() {
    this.selectionStart = 0;
    this.selectionEnd = getText().length();

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 8
Source File: TextComponent.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 9
Source File: TextComponent.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 10
Source File: TextComponent.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 11
Source File: TextComponent.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * {@code endPosition} - {@code startPosition}, so the
 * character at {@code endPosition} is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
 *               character ({@code char} value) to be selected
 * @param        selectionEnd the zero-based end position of the
 *               text to be selected; the character ({@code char} value) at
 *               {@code selectionEnd} is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 12
Source File: TextComponent.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * {@code endPosition} - {@code startPosition}, so the
 * character at {@code endPosition} is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
 *               character ({@code char} value) to be selected
 * @param        selectionEnd the zero-based end position of the
 *               text to be selected; the character ({@code char} value) at
 *               {@code selectionEnd} is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 13
Source File: TextComponent.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 14
Source File: TextComponent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 15
Source File: TextComponent.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 16
Source File: TextComponent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 17
Source File: TextComponent.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 18
Source File: TextComponent.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 19
Source File: TextComponent.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}
 
Example 20
Source File: TextComponent.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the text between the specified start and end positions.
 * <p>
 * This method sets the start and end positions of the
 * selected text, enforcing the restriction that the start position
 * must be greater than or equal to zero.  The end position must be
 * greater than or equal to the start position, and less than or
 * equal to the length of the text component's text.  The
 * character positions are indexed starting with zero.
 * The length of the selection is
 * <code>endPosition</code> - <code>startPosition</code>, so the
 * character at <code>endPosition</code> is not selected.
 * If the start and end positions of the selected text are equal,
 * all text is deselected.
 * <p>
 * If the caller supplies values that are inconsistent or out of
 * bounds, the method enforces these constraints silently, and
 * without failure. Specifically, if the start position or end
 * position is greater than the length of the text, it is reset to
 * equal the text length. If the start position is less than zero,
 * it is reset to zero, and if the end position is less than the
 * start position, it is reset to the start position.
 *
 * @param        selectionStart the zero-based index of the first
                   character (<code>char</code> value) to be selected
 * @param        selectionEnd the zero-based end position of the
                   text to be selected; the character (<code>char</code> value) at
                   <code>selectionEnd</code> is not selected
 * @see          java.awt.TextComponent#setSelectionStart
 * @see          java.awt.TextComponent#setSelectionEnd
 * @see          java.awt.TextComponent#selectAll
 */
public synchronized void select(int selectionStart, int selectionEnd) {
    String text = getText();
    if (selectionStart < 0) {
        selectionStart = 0;
    }
    if (selectionStart > text.length()) {
        selectionStart = text.length();
    }
    if (selectionEnd > text.length()) {
        selectionEnd = text.length();
    }
    if (selectionEnd < selectionStart) {
        selectionEnd = selectionStart;
    }

    this.selectionStart = selectionStart;
    this.selectionEnd = selectionEnd;

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.select(selectionStart, selectionEnd);
    }
}