textbox.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 437 行 · 第 1/2 页

JAVA
437
字号
     * The string is     * inserted just prior to the character indicated by the     * <code>position</code> parameter, where zero specifies the first     * character of the contents of the <code>TextBox</code>.  If     * <code>position</code> is     * less than or equal to zero, the insertion occurs at the beginning of     * the contents, thus effecting a prepend operation.  If     * <code>position</code> is greater than or equal to the current size of     * the contents, the insertion occurs immediately after the end of the     * contents, thus effecting an append operation.  For example,     * <code>text.insert(s, text.size())</code> always appends the string      * <code>s</code> to the current contents.     *      * <p>The current size of the contents is increased by the number of     * inserted characters. The resulting string must fit within the current     * maximum capacity. </p>     *     * <p>If the application needs to simulate typing of characters it can     * determining the location of the current insertion point     * (&quot;caret&quot;)     * using the with {@link #getCaretPosition() getCaretPosition()} method.       * For example,     * <code>text.insert(s, text.getCaretPosition())</code> inserts the string      * <code>s</code> at the current caret position.</p>     *     * @param src the <code>String</code> to be inserted     * @param position the position at which insertion is to occur     *      * @throws IllegalArgumentException if the resulting contents     * would be illegal for the current     * <a href="TextField.html#constraints">input constraints</a>     * @throws IllegalArgumentException if the insertion would     * exceed the current     * maximum capacity     * @throws NullPointerException if <code>src</code> is <code>null</code>     */    public void insert(String src, int position)  {        textField.insert(src, position);    }    /**     * Inserts a subrange of an array of characters into the contents of     * the <code>TextBox</code>.  The <code>offset</code> and     * <code>length</code> parameters indicate the subrange of     * the data array to be used for insertion. Behavior is otherwise     * identical to {@link #insert(String, int) insert(String, int)}.      *     * <p>The <code>offset</code> and <code>length</code> parameters must     * specify a valid range of characters within     * the character array <code>data</code>.     * The <code>offset</code> parameter must be within the     * range <code>[0..(data.length)]</code>, inclusive.     * The <code>length</code> parameter     * must be a non-negative integer such that     * <code>(offset + length) &lt;= data.length</code>.</p>     *      * @param data the source of the character data     * @param offset the beginning of the region of characters to copy     * @param length the number of characters to copy     * @param position the position at which insertion is to occur     *      * @throws ArrayIndexOutOfBoundsException if <code>offset</code>     * and <code>length</code> do not     * specify a valid range within the data array     * @throws IllegalArgumentException if the resulting contents     * would be illegal for the current     * <a href="TextField.html#constraints">input constraints</a>     * @throws IllegalArgumentException if the insertion would     * exceed the current     * maximum capacity     * @throws NullPointerException if <code>data</code> is <code>null</code>     */    public void insert(char[] data, int offset, int length, int position)  {        textField.insert(data, offset, length, position);    }    /**     * Deletes characters from the <code>TextBox</code>.     *     * <p>The <code>offset</code> and <code>length</code> parameters must     * specify a valid range of characters within     * the contents of the <code>TextBox</code>.     * The <code>offset</code> parameter must be within the     * range <code>[0..(size())]</code>, inclusive.     * The <code>length</code> parameter     * must be a non-negative integer such that     * <code>(offset + length) &lt;= size()</code>.</p>     *      * @param offset the beginning of the region to be deleted     * @param length the number of characters to be deleted     *     * @throws IllegalArgumentException if the resulting contents     * would be illegal for the current     * <a href="TextField.html#constraints">input constraints</a>     * @throws StringIndexOutOfBoundsException if <code>offset</code>     * and <code>length</code> do not     * specify a valid range within the contents of the <code>TextBox</code>     */    public void delete(int offset, int length) {        textField.delete(offset, length);    }    /**     * Returns the maximum size (number of characters) that can be     * stored in this <code>TextBox</code>.     * @return the maximum size in characters     * @see #setMaxSize     */    public int getMaxSize() {        return textField.getMaxSize();    }    /**     * Sets the maximum size (number of characters) that can be     * contained in this     * <code>TextBox</code>. If the current contents of the     * <code>TextBox</code> are larger than     * <code>maxSize</code>, the contents are truncated to fit.     *     * @param maxSize the new maximum size     *     * @return assigned maximum capacity - may be smaller than requested.     * @throws IllegalArgumentException if <code>maxSize</code> is zero or less.     * @throws IllegalArgumentException if the contents     * after truncation would be illegal for the current      * <a href="TextField.html#constraints">input constraints</a>     * @see #getMaxSize     */    public int setMaxSize(int maxSize)  {        return textField.setMaxSize(maxSize);    }    /**     * Gets the number of characters that are currently stored in this     * <code>TextBox</code>.     * @return the number of characters     */    public int size() {        // returns a value relative to the display text including formatting        return textField.size();    }    /**     * Gets the current input position.  For some UIs this may block and ask     * the user for the intended caret position, and on other UIs this may     * simply return the current caret position.     *      * @return the current caret position, <code>0</code> if at the beginning     */    public int getCaretPosition() {        // returns a value relative to the flat input text        return textField.getCaretPosition();    }    /**     * Sets the input constraints of the <code>TextBox</code>. If the     * current contents     * of the <code>TextBox</code> do not match the new constraints,     * the contents are     * set to empty.     *     * @param constraints see     * <a href="TextField.html#constraints">input constraints</a>     *     * @throws IllegalArgumentException if the value of the constraints     * parameter is invalid     * @see #getConstraints     */    public void setConstraints(int constraints) {        textField.setConstraints(constraints);    }    /**     * Gets the current input constraints of the <code>TextBox</code>.     *     * @return the current constraints value (see     * <a href="TextField.html#constraints">input constraints</a>)     * @see #setConstraints     */    public int getConstraints() {        return textField.getConstraints();    }    /**     * Sets a hint to the implementation as to the input mode that should be     * used when the user initiates editing of this     * <code>TextBox</code>. The     * <code>characterSubset</code> parameter names a subset of Unicode     * characters that is used by the implementation to choose an initial     * input mode.  If <code>null</code> is passed, the implementation should     * choose a default input mode.     *     * <p>See <a href="TextField#modes">Input Modes</a> for a full      * explanation of input modes. </p>     *     * @param characterSubset a string naming a Unicode character subset,     * or <code>null</code>     *     */    public void setInitialInputMode(String characterSubset) {        textField.setInitialInputMode(characterSubset);    }    /*     * package private     */    /** text field object to put on the form */    TextField textField;    /** Look & feel object associated with this TextBox */    FormLF textBoxLF;} // class TextBox

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?