本文整理汇总了Java中javax.swing.text.PlainDocument.getText方法的典型用法代码示例。如果您正苦于以下问题:Java PlainDocument.getText方法的具体用法?Java PlainDocument.getText怎么用?Java PlainDocument.getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.PlainDocument
的用法示例。
在下文中一共展示了PlainDocument.getText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inputChange
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
private void inputChange(PlainDocument doc, JTextArea area, String directionToCompare) {
try {
String str = doc.getText(doc.getLength() - 2, 1);
if (str.equals(directionToCompare)) {
if (movementCounter < 9) {
movementCounter++;
doc.remove(doc.getLength() - 1, 1);
area.append(Integer.toString(movementCounter));
}
else {
movementCounter = 0;
area.append(directionToCompare + Integer.toString(movementCounter));
}
}
else {
movementCounter = 0;
area.append(directionToCompare + Integer.toString(movementCounter));
}
}
catch (BadLocationException e) {
e.printStackTrace();
}
}
示例2: getLineAt
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
/**
* Return the line of text at the given position. The returned value may
* be null. It will not contain the trailing new-line character.
*
* @param doc
* @param pos
* @return
*/
public static String getLineAt(PlainDocument doc, int pos) {
String line = null;
int start = doc.getParagraphElement(pos).getStartOffset();
int end = doc.getParagraphElement(pos).getEndOffset();
try {
line = doc.getText(start, end - start);
if (line != null && line.endsWith("\n")) {
line = line.substring(0, line.length() - 1);
}
} catch (BadLocationException e) {
LOG.error(e.getMessage(), e);
}
return line;
}
示例3: convert
import javax.swing.text.PlainDocument; //导入方法依赖的package包/类
@Override
public String convert(final PlainDocument plainDocument) throws RuntimeException {
try {
return plainDocument.getText(0, plainDocument.getLength());
} catch (final BadLocationException exception) {
return ""; //$NON-NLS-1$
}
}