本文整理汇总了Java中javax.swing.text.BadLocationException.initCause方法的典型用法代码示例。如果您正苦于以下问题:Java BadLocationException.initCause方法的具体用法?Java BadLocationException.initCause怎么用?Java BadLocationException.initCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.BadLocationException
的用法示例。
在下文中一共展示了BadLocationException.initCause方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isRowEmpty
import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
public static boolean isRowEmpty(CharSequence text, int offset) throws BadLocationException {
try {
if (offset < text.length()) {
char c = text.charAt(offset);
if (!(c == '\n' || (c == '\r' && (offset == text.length()-1 || text.charAt(offset+1) == '\n')))) {
return false;
}
}
if (!(offset == 0 || text.charAt(offset-1) == '\n')) {
// There's previous stuff on this line
return false;
}
return true;
} catch (Exception ex) {
BadLocationException ble = new BadLocationException(offset + " out of " + text.length(), offset);
ble.initCause(ex);
throw ble;
}
}
示例2: getRowStart
import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
public static int getRowStart(CharSequence text, int offset) throws BadLocationException {
try {
// Search backwards
for (int i = offset-1; i >= 0; i--) {
char c = text.charAt(i);
if (c == '\n') {
return i+1;
}
}
return 0;
} catch (Exception ex) {
BadLocationException ble = new BadLocationException(offset + " out of " + text.length(), offset);
ble.initCause(ex);
throw ble;
}
}
示例3: getRowEnd
import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
public static int getRowEnd(CharSequence text, int offset) throws BadLocationException {
try {
// Search backwards
for (int i = offset; i < text.length(); i++) {
char c = text.charAt(i);
if (c == '\n') {
return i;
}
}
return text.length();
} catch (Exception ex) {
BadLocationException ble = new BadLocationException(offset + " out of " + text.length(), offset);
ble.initCause(ex);
throw ble;
}
}
示例4: getText
import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
/**
* Get a portion of text of the given document as char sequence.
* <br>
*
* @param doc document for which the charsequence is being obtained.
* @param offset starting offset of the charsequence to obtain.
* @param length length of the charsequence to obtain. It must be <code>>= 0</code>
* and <code><doc.getLength() + 1</code>.
* @return non-null character sequence.
* @exception BadLocationException some portion of the given range
* was not a valid part of the document. The location in the exception
* is the first bad position encountered.
* <br>
* The returned character sequence should only be accessed under
* document's readlock (or writelock).
*/
public static CharSequence getText(Document doc, int offset, int length) throws BadLocationException {
CharSequence text = getText(doc);
try {
return text.subSequence(offset, offset + length);
} catch (IndexOutOfBoundsException e) {
int badOffset = offset;
if (offset >= 0 && offset + length > text.length()) {
badOffset = length;
}
BadLocationException ble = new BadLocationException(e.getMessage(), badOffset);
ble.initCause(e);
throw ble;
}
}