本文整理汇总了Java中java.awt.peer.TextComponentPeer.setCaretPosition方法的典型用法代码示例。如果您正苦于以下问题:Java TextComponentPeer.setCaretPosition方法的具体用法?Java TextComponentPeer.setCaretPosition怎么用?Java TextComponentPeer.setCaretPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.peer.TextComponentPeer
的用法示例。
在下文中一共展示了TextComponentPeer.setCaretPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCaretPosition
import java.awt.peer.TextComponentPeer; //导入方法依赖的package包/类
/**
* Sets the position of the text insertion caret.
* The caret position is constrained to be between 0
* and the last character of the text, inclusive.
* If the passed-in value is greater than this range,
* the value is set to the last character (or 0 if
* the <code>TextComponent</code> contains no text)
* and no error is returned. If the passed-in value is
* less than 0, an <code>IllegalArgumentException</code>
* is thrown.
*
* @param position the position of the text insertion caret
* @exception IllegalArgumentException if <code>position</code>
* is less than zero
* @since JDK1.1
*/
public synchronized void setCaretPosition(int position) {
if (position < 0) {
throw new IllegalArgumentException("position less than zero.");
}
int maxposition = getText().length();
if (position > maxposition) {
position = maxposition;
}
TextComponentPeer peer = (TextComponentPeer)this.peer;
if (peer != null) {
peer.setCaretPosition(position);
} else {
select(position, position);
}
}
示例2: setCaretPosition
import java.awt.peer.TextComponentPeer; //导入方法依赖的package包/类
/**
* Sets the position of the text insertion caret.
* The caret position is constrained to be between 0
* and the last character of the text, inclusive.
* If the passed-in value is greater than this range,
* the value is set to the last character (or 0 if
* the {@code TextComponent} contains no text)
* and no error is returned. If the passed-in value is
* less than 0, an {@code IllegalArgumentException}
* is thrown.
*
* @param position the position of the text insertion caret
* @exception IllegalArgumentException if {@code position}
* is less than zero
* @since 1.1
*/
public synchronized void setCaretPosition(int position) {
if (position < 0) {
throw new IllegalArgumentException("position less than zero.");
}
int maxposition = getText().length();
if (position > maxposition) {
position = maxposition;
}
TextComponentPeer peer = (TextComponentPeer)this.peer;
if (peer != null) {
peer.setCaretPosition(position);
} else {
select(position, position);
}
}
示例3: setCaretPosition
import java.awt.peer.TextComponentPeer; //导入方法依赖的package包/类
/**
* Sets the position of the text insertion caret.
* The caret position is constrained to be between 0
* and the last character of the text, inclusive.
* If the passed-in value is greater than this range,
* the value is set to the last character (or 0 if
* the <code>TextComponent</code> contains no text)
* and no error is returned. If the passed-in value is
* less than 0, an <code>IllegalArgumentException</code>
* is thrown.
*
* @param position the position of the text insertion caret
* @exception IllegalArgumentException if <code>position</code>
* is less than zero
* @since JDK1.1
*/
public synchronized void setCaretPosition(int position) {
if (position < 0) {
throw new IllegalArgumentException("position less than zero.");
}
int maxposition = getText().length();
if (position > maxposition) {
position = maxposition;
}
TextComponentPeer peer = (TextComponentPeer)this.peer;
if (peer != null) {
peer.setCaretPosition(position);
} else {
select(position, position);
}
}
示例4: setCaretPosition
import java.awt.peer.TextComponentPeer; //导入方法依赖的package包/类
/**
* Sets the caret position to the specified value.
*
* @param caretPosition The new caret position.
*
* @exception IllegalArgumentException If the value supplied for position
* is less than zero.
*
* @since 1.1
*/
public synchronized void setCaretPosition(int caretPosition)
{
if (caretPosition < 0)
throw new IllegalArgumentException();
TextComponentPeer tcp = (TextComponentPeer) getPeer();
if (tcp != null)
tcp.setCaretPosition(caretPosition);
}