本文整理汇总了Java中java.awt.peer.TextComponentPeer类的典型用法代码示例。如果您正苦于以下问题:Java TextComponentPeer类的具体用法?Java TextComponentPeer怎么用?Java TextComponentPeer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextComponentPeer类属于java.awt.peer包,在下文中一共展示了TextComponentPeer类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getCaretPosition
import java.awt.peer.TextComponentPeer; //导入依赖的package包/类
/**
* Returns 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 text or caret have not been set, the default
* caret position is 0.
*
* @return the position of the text insertion caret
* @see #setCaretPosition(int)
* @since JDK1.1
*/
public synchronized int getCaretPosition() {
TextComponentPeer peer = (TextComponentPeer)this.peer;
int position = 0;
if (peer != null) {
position = peer.getCaretPosition();
} else {
position = selectionStart;
}
int maxposition = getText().length();
if (position > maxposition) {
position = maxposition;
}
return position;
}
示例3: writeObject
import java.awt.peer.TextComponentPeer; //导入依赖的package包/类
/**
* Writes default serializable fields to stream. Writes
* a list of serializable TextListener(s) as optional data.
* The non-serializable TextListener(s) are detected and
* no attempt is made to serialize them.
*
* @serialData Null terminated sequence of zero or more pairs.
* A pair consists of a String and Object.
* The String indicates the type of object and
* is one of the following :
* textListenerK indicating and TextListener object.
*
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
* @see java.awt.Component#textListenerK
*/
private void writeObject(java.io.ObjectOutputStream s)
throws IOException
{
// Serialization support. Since the value of the fields
// selectionStart, selectionEnd, and text aren't necessarily
// up to date, we sync them up with the peer before serializing.
TextComponentPeer peer = (TextComponentPeer)this.peer;
if (peer != null) {
text = peer.getText();
selectionStart = peer.getSelectionStart();
selectionEnd = peer.getSelectionEnd();
}
s.defaultWriteObject();
AWTEventMulticaster.save(s, textListenerK, textListener);
s.writeObject(null);
}
示例4: setText
import java.awt.peer.TextComponentPeer; //导入依赖的package包/类
/**
* Sets the text that is presented by this
* text component to be the specified text.
* @param t the new text;
* if this parameter is {@code null} then
* the text is set to the empty string ""
* @see java.awt.TextComponent#getText
*/
public synchronized void setText(String t) {
if (t == null) {
t = "";
}
TextComponentPeer peer = (TextComponentPeer)this.peer;
if (peer != null) {
text = peer.getText();
// Please note that we do not want to post an event
// if TextArea.setText() or TextField.setText() replaces text
// by same text, that is, if component's text remains unchanged.
if (!t.equals(text)) {
text = t;
peer.setText(text);
}
} else {
text = t;
}
}
示例5: 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);
}
}
示例6: getCaretPosition
import java.awt.peer.TextComponentPeer; //导入依赖的package包/类
/**
* Returns 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 text or caret have not been set, the default
* caret position is 0.
*
* @return the position of the text insertion caret
* @see #setCaretPosition(int)
* @since 1.1
*/
public synchronized int getCaretPosition() {
TextComponentPeer peer = (TextComponentPeer)this.peer;
int position = 0;
if (peer != null) {
position = peer.getCaretPosition();
} else {
position = selectionStart;
}
int maxposition = getText().length();
if (position > maxposition) {
position = maxposition;
}
return position;
}
示例7: select
import java.awt.peer.TextComponentPeer; //导入依赖的package包/类
/**
* This method sets the selected text range to the text between the
* specified start and end positions. Illegal values for these
* positions are silently fixed.
*
* @param selectionStart The new start position for the selected text.
* @param selectionEnd The new end position for the selected text.
*/
public synchronized void select(int selectionStart, int selectionEnd)
{
if (selectionStart < 0)
selectionStart = 0;
if (selectionStart > getText().length())
selectionStart = text.length();
if (selectionEnd > text.length())
selectionEnd = text.length();
if (selectionStart > selectionEnd)
selectionStart = selectionEnd;
this.selectionStart = selectionStart;
this.selectionEnd = selectionEnd;
TextComponentPeer tcp = (TextComponentPeer) getPeer();
if (tcp != null)
tcp.select(selectionStart, selectionEnd);
}
示例8: select
import java.awt.peer.TextComponentPeer; //导入依赖的package包/类
/**
* This method sets the selected text range to the text between the
* specified start and end positions. Illegal values for these
* positions are silently fixed.
*
* @param selectionStart The new start position for the selected text.
* @param selectionEnd The new end position for the selected text.
*/
public synchronized void select(int selectionStart, int selectionEnd)
{
if (selectionStart < 0)
selectionStart = 0;
if (selectionStart > getText().length())
selectionStart = text.length();
if (selectionEnd > text.length())
selectionEnd = text.length();
if (selectionStart > selectionEnd)
selectionStart = selectionEnd;
this.selectionStart = selectionStart;
this.selectionEnd = selectionEnd;
TextComponentPeer tcp = (TextComponentPeer) getPeer();
if (tcp != null)
tcp.select(selectionStart, selectionEnd);
}
示例9: 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);
}
}
示例10: getCaretPosition
import java.awt.peer.TextComponentPeer; //导入依赖的package包/类
/**
* Returns 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 text or caret have not been set, the default
* caret position is 0.
*
* @return the position of the text insertion caret
* @see #setCaretPosition(int)
* @since JDK1.1
*/
public synchronized int getCaretPosition() {
TextComponentPeer peer = (TextComponentPeer)this.peer;
int position = 0;
if (peer != null) {
position = peer.getCaretPosition();
} else {
position = selectionStart;
}
int maxposition = getText().length();
if (position > maxposition) {
position = maxposition;
}
return position;
}
示例11: writeObject
import java.awt.peer.TextComponentPeer; //导入依赖的package包/类
/**
* Writes default serializable fields to stream. Writes
* a list of serializable TextListener(s) as optional data.
* The non-serializable TextListener(s) are detected and
* no attempt is made to serialize them.
*
* @serialData Null terminated sequence of zero or more pairs.
* A pair consists of a String and Object.
* The String indicates the type of object and
* is one of the following :
* textListenerK indicating and TextListener object.
*
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
* @see java.awt.Component#textListenerK
*/
private void writeObject(java.io.ObjectOutputStream s)
throws IOException
{
// Serialization support. Since the value of the fields
// selectionStart, selectionEnd, and text aren't necessarily
// up to date, we sync them up with the peer before serializing.
TextComponentPeer peer = (TextComponentPeer)this.peer;
if (peer != null) {
text = peer.getText();
selectionStart = peer.getSelectionStart();
selectionEnd = peer.getSelectionEnd();
}
s.defaultWriteObject();
AWTEventMulticaster.save(s, textListenerK, textListener);
s.writeObject(null);
}