javax.swing.text.AbstractDocument.getLength()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中javax.swing.text.AbstractDocument.getLength()方法的一些代码示例,展示了AbstractDocument.getLength()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractDocument.getLength()方法的具体详情如下:
包路径:javax.swing.text.AbstractDocument
类名称:AbstractDocument
方法名:getLength

AbstractDocument.getLength介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

import javax.swing.text.PlainDocument

public class JTextFieldLimit extends PlainDocument {
 private int limit;

 JTextFieldLimit(int limit) {
  super();
  this.limit = limit;
  }

 public void insertString( int offset, String  str, AttributeSet attr ) throws BadLocationException {
  if (str == null) return;

  if ((getLength() + str.length()) <= limit) {
   super.insertString(offset, str, attr);
  }
 }
}

代码示例来源:origin: stackoverflow.com

return;
if ((getLength() + str.length()) <= limit) {
 super.insertString(offset, str, attr);

代码示例来源:origin: stackoverflow.com

super.insertString(offset, str, a);
String text = getText(0, getLength());
int before = findLastNonWordChar(text, offset);
if (before < 0) before = 0;
super.remove(offs, len);
String text = getText(0, getLength());
int before = findLastNonWordChar(text, offs);
if (before < 0) before = 0;

代码示例来源:origin: ron190/jsql-injection

/**
 * Seek to the given position in the document.
 *
 * @param n the offset to which to seek.
 */
public void seek(long n){
  if (n <= this.document.getLength()){
    this.position = n;
  } else {
    this.position = this.document.getLength();
  }
}

代码示例来源:origin: ron190/jsql-injection

/**
 * Skip characters of input.
 * This method will always skip the maximum number of characters unless
 * the end of the file is reached.
 *
 * @param n number of characters to skip.
 * @return the actual number of characters skipped.
 */
@Override
public long skip(long n){
  if (this.position + n <= this.document.getLength()){
    this.position += n;
    return n;
  } else {
    long oldPos = this.position;
    this.position = this.document.getLength();
    return this.document.getLength() - oldPos;
  }
}

代码示例来源:origin: ron190/jsql-injection

if (this.position < this.document.getLength()){
  int length = len;
  if (this.position + length >= this.document.getLength()){
    length = this.document.getLength() - (int)this.position;

代码示例来源:origin: ron190/jsql-injection

/**
 * Read a single character.
 *
 * @return the character or -1 if the end of the document has been reached.
 */
@Override
public int read(){
  if (this.position < this.document.getLength()){
    try {
      char c = this.document.getText((int)this.position, 1).charAt(0);
      this.position++;
      return c;
    } catch (BadLocationException e){
      // Ignore
      IgnoreMessageException exceptionIgnored = new IgnoreMessageException(e);
      LOGGER.trace(exceptionIgnored, exceptionIgnored);
      return -1;
    }
  } else {
    return -1;
  }
}

代码示例来源:origin: net.sf.jt400/jt400

/**
Returns the length of the document.

@return The length of the document in characters.
**/
  public synchronized int getLength ()
  {
    return document_.getLength ();
  }

代码示例来源:origin: net.sf.jt400/jt400

/**
Returns the length of the document.

@return The length of the document in characters.
**/
  public synchronized int getLength ()
  {
    return document_.getLength ();
  }

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/ostermiller-syntax

/**
   * Seek to the given position in the document.
   *
   * @param n the offset to which to seek.
   */
  public void seek(long n){
    if (n <= document.getLength()){
      position = n;
    } else {
      position = document.getLength();
    }
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/ostermiller-syntax

/**
 * Skip characters of input.
 * This method will always skip the maximum number of characters unless
 * the end of the file is reached.
 *
 * @param n number of characters to skip.
 * @return the actual number of characters skipped.
 */
public long skip(long n){
  if (position + n <= document.getLength()){
    position += n;
    return n;
  } else {
    long oldPos = position;
    position = document.getLength();
    return (document.getLength() - oldPos);
  }
}

代码示例来源:origin: stackoverflow.com

if( getLength() > limit  )
  super.remove(limit, getLength() - limit);

代码示例来源:origin: stackoverflow.com

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class JTextFieldLimit extends PlainDocument { //Added limited textfield so you can only enter one char
  private static final long serialVersionUID = 3452547874756361487L;
  private int limit;

  public JTextFieldLimit(int limit) {
    super();
    this.limit = limit;
  }

  public void insertString(int offset, String  str, AttributeSet attr) throws BadLocationException {
    if (str == null)
      return;

    if ((getLength() + str.length()) <= limit) {
      super.insertString(offset, str, attr);
    }

  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/ostermiller-syntax

/**
 * Read a single character.
 *
 * @return the character or -1 if the end of the document has been reached.
 */
public int read(){
  if (position < document.getLength()){
    try {
      char c = document.getText((int)position, 1).charAt(0);
      position++;
      return c;
    } catch (BadLocationException x){
      return -1;
    }
  } else {
    return -1;
  }
}

代码示例来源:origin: stackoverflow.com

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.AttributeSet;
import javax.swing.text.PlainDocument;

/**
*
* @author cpp-qt
*/
public class HexDocument extends PlainDocument {

private String text = "";

@Override
public void insertString(int offset, String txt, AttributeSet a) {
  try {
    text = getText(0, getLength());
    if ((text + txt).matches("[0-9a-fA-F]{0,7}")) {
      super.insertString(offset, txt, a);
    }
   } catch (Exception ex) {
    Logger.getLogger(HexDocument.class.getName()).log(Level.SEVERE, null, ex);
   }

  }
}

代码示例来源:origin: net.sf.jt400/jt400

/**
Writes the contents of the document to the data queue.The entry replaces the current content. System and path must be set prior
to calling this method.
**/
  public void write ()
  {
    workingEventSupport_.fireStartWorking ();

    // Write the contents.
    try {
      dataQueue_.write (document_.getText (0, document_.getLength ()));
    }
    catch (Exception e) {
      errorEventSupport_.fireError (e);
    }

    workingEventSupport_.fireStopWorking ();
  }

代码示例来源:origin: net.sf.jt400/jt400

/**
Writes the contents of the document to the data queue.The entry replaces the current content. System and path must be set prior
to calling this method.

@param key  The string that contains the key for this entry.
**/
  public void write (String key)
  {
    workingEventSupport_.fireStartWorking ();

    // Write the contents.
    try {
      dataQueue_.write (key, document_.getText (0, document_.getLength ()));
    }
    catch (Exception e) {
      errorEventSupport_.fireError (e);
    }

    workingEventSupport_.fireStopWorking ();
  }

代码示例来源:origin: net.sf.jt400/jt400

document_.remove (0, document_.getLength ());

代码示例来源:origin: net.sf.jt400/jt400

document_.remove (0, document_.getLength ());

代码示例来源:origin: net.sf.jt400/jt400

document_.remove (0, document_.getLength ());

相关文章