本文整理了Java中javax.swing.text.BadLocationException.printStackTrace()
方法的一些代码示例,展示了BadLocationException.printStackTrace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BadLocationException.printStackTrace()
方法的具体详情如下:
包路径:javax.swing.text.BadLocationException
类名称:BadLocationException
方法名:printStackTrace
暂无
代码示例来源:origin: stackoverflow.com
JEditorPane pane = new JEditorPane();
/* ... Other stuff ... */
public void append(String s) {
try {
Document doc = pane.getDocument();
doc.insertString(doc.getLength(), s, null);
} catch(BadLocationException exc) {
exc.printStackTrace();
}
}
代码示例来源:origin: groovy/groovy-core
public void actionPerformed(ActionEvent ae) {
JTextComponent tComp = (JTextComponent) ae.getSource();
if (tComp.getDocument() instanceof StyledDocument) {
doc = (StyledDocument) tComp.getDocument();
try {
doc.getText(0, doc.getLength(), segment);
}
catch (Exception e) {
// should NEVER reach here
e.printStackTrace();
}
int offset = tComp.getCaretPosition();
int index = findTabLocation(offset);
buffer.delete(0, buffer.length());
buffer.append('\n');
if (index > -1) {
for (int i = 0; i < index + 4; i++) {
buffer.append(' ');
}
}
try {
doc.insertString(offset, buffer.toString(),
doc.getDefaultRootElement().getAttributes());
}
catch (BadLocationException ble) {
ble.printStackTrace();
}
}
}
代码示例来源:origin: groovy/groovy-core
ble.printStackTrace();
代码示例来源:origin: groovy/groovy-core
ble.printStackTrace();
代码示例来源:origin: groovy/groovy-core
public void paint(Graphics g) {
if (isVisible()) {
try {
JTextComponent component = getComponent();
Rectangle r = component.getUI().modelToView(component, getDot());
Color c = g.getColor();
g.setColor(component.getBackground());
g.setXORMode(component.getCaretColor());
r.setBounds(r.x, r.y,
g.getFontMetrics().charWidth('w'),
g.getFontMetrics().getHeight());
g.fillRect(r.x, r.y, r.width, r.height);
g.setPaintMode();
g.setColor(c);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* Reads the single character at the current position in the document.
*/
@Override
public int read() {
if(position>=document.getLength()) {
return -1; // Read past end of document.
}
try {
document.getText((int)position,1, segment);
position++;
return segment.array[segment.offset];
} catch (BadLocationException ble) {
/* Should never happen?? */
ble.printStackTrace();
return -1;
}
}
代码示例来源:origin: apache/pdfbox
private String getWord(int offset)
{
try
{
int start = Utilities.getWordStart(textComponent, offset);
int end = Utilities.getWordEnd(textComponent, offset);
return textComponent.getDocument().getText(start, end - start + 1).trim();
}
catch (BadLocationException e)
{
e.printStackTrace();
}
return null;
}
代码示例来源:origin: apache/pdfbox
private String getRowText(int offset)
{
try
{
int rowStart = Utilities.getRowStart(textComponent, offset);
int rowEnd = Utilities.getRowEnd(textComponent, offset);
return textComponent.getDocument().getText(rowStart, rowEnd - rowStart + 1);
}
catch (BadLocationException e)
{
e.printStackTrace();
}
return null;
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
@Override
public void mousePressed(MouseEvent e) {
if (bookmarkingEnabled && bookmarkIcon!=null) {
try {
int line = viewToModelLine(e.getPoint());
if (line>-1) {
toggleBookmark(line);
}
} catch (BadLocationException ble) {
ble.printStackTrace(); // Never happens
}
}
}
代码示例来源:origin: apache/pdfbox
private void scrollToWord(int offset)
{
try
{
textComponent.scrollRectToVisible(textComponent.modelToView(offset));
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
private int rowAtPoint(Point p) {
int line = 0;
try {
int offs = textArea.viewToModel(p);
if (offs>-1) {
line = textArea.getLineOfOffset(offs);
}
} catch (BadLocationException ble) {
ble.printStackTrace(); // Never happens
}
return line;
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* {@inheritDoc}
*/
@Override
public String toString() {
try {
return doc.getText(start, length());
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
return "";
}
}
代码示例来源:origin: apache/pdfbox
private void writeToken(Object obj, StyledDocument docu)
{
try
{
if (obj instanceof Operator)
{
addOperators(obj, docu);
}
else
{
writeOperand(obj, docu);
}
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
代码示例来源:origin: apache/pdfbox
private void search(DocumentEvent documentEvent)
{
try
{
String word = documentEvent.getDocument().getText(0, documentEvent.getDocument().getLength());
if (word.isEmpty())
{
nextAction.setEnabled(false);
previousAction.setEnabled(false);
searchPanel.reset();
textComponent.getHighlighter().removeAllHighlights();
return;
}
search(word);
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
Gutter gutter = RSyntaxUtilities.getGutter(textArea);
if (gutter!=null) {
int line = textArea.getCaretLineNumber();
try {
gutter.toggleBookmark(line);
} catch (BadLocationException ble) { // Never happens
UIManager.getLookAndFeel().
provideErrorFeedback(textArea);
ble.printStackTrace();
}
}
}
代码示例来源:origin: apache/pdfbox
private StyledDocument getDocument(InputStream inputStream, String encoding)
{
StyledDocument docu = new DefaultStyledDocument();
if (inputStream != null)
{
String data = getStringOfStream(inputStream, encoding);
try
{
docu.insertString(0, data, null);
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
return docu;
}
代码示例来源:origin: apache/pdfbox
private void changeHighlighter(int index, Highlighter.HighlightPainter newPainter)
{
Highlighter highlighter = textComponent.getHighlighter();
Highlighter.Highlight highLight = highlights.get(index);
highlighter.removeHighlight(highLight);
try
{
highlighter.addHighlight(highLight.getStartOffset(), highLight.getEndOffset(), newPainter);
highlights.set(index, highlighter.getHighlights()[highlighter.getHighlights().length - 1]);
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* Returns the last visible offset in this text area. This may not be the
* length of the document if code folding is enabled.
*
* @return The last visible offset in this text area.
*/
public int getLastVisibleOffset() {
if (isCodeFoldingEnabled()) {
int lastVisibleLine = foldManager.getLastVisibleLine();
if (lastVisibleLine<getLineCount()-1) { // Not the last line
try {
return getLineEndOffset(lastVisibleLine) - 1;
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
}
}
}
return getDocument().getLength();
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
@Override
public void removeUpdate(DocumentEvent e) {
// Removing text from the visible line of a folded Fold causes that
// Fold to unfold. We only need to check the removal offset since
// that's the new caret position.
int offs = e.getOffset();
try {
int lastLineModified = textArea.getLineOfOffset(offs);
//System.out.println(">>> " + lastLineModified);
Fold fold = getFoldForLine(lastLineModified);
//System.out.println("&&& " + fold);
if (fold!=null && fold.isCollapsed()) {
fold.toggleCollapsedState();
}
} catch (BadLocationException ble) {
ble.printStackTrace(); // Never happens
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
try {
// We use the elements instead of calling getLineOfOffset(),
// etc. to speed things up just a tad (i.e. micro-optimize).
Document document = textArea.getDocument();
int caretPosition = textArea.getCaretPosition();
Element map = document.getDefaultRootElement();
int currentLineNum = map.getElementIndex(caretPosition);
Element currentLineElement = map.getElement(currentLineNum);
// Always take -1 as we don't want to remove the newline.
int currentLineEnd = currentLineElement.getEndOffset()-1;
if (caretPosition<currentLineEnd) {
document.remove(caretPosition,
currentLineEnd-caretPosition);
}
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
内容来源于网络,如有侵权,请联系作者删除!