本文整理了Java中javax.swing.JTextArea.getLineOfOffset()
方法的一些代码示例,展示了JTextArea.getLineOfOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextArea.getLineOfOffset()
方法的具体详情如下:
包路径:javax.swing.JTextArea
类名称:JTextArea
方法名:getLineOfOffset
暂无
代码示例来源:origin: stackoverflow.com
public Point getCaretPixelPosition(JTextArea a) {
try {
int cpos = a.getCaretPosition();
Font font = a.getStyledDocument().getFont(a.getStyledDocument().getLogicalStyle(cpos));
FontMetrics metrics = getFontMetrics(font);
int lineNum = a.getLineOfOffset(cpos);
int y = lineNum * metrics.getHeight();
int lineStart = a.getLineStartOffset(lineNum);
int x = metrics.stringWidth(a.getText().substring(lineStart, cpos));
return new Point(x,y);
} catch(BadLocationException e) {}
return null;
}
代码示例来源:origin: org.zaproxy/zap
int finalStartPos = start;
try {
finalStartPos += view.getLineOfOffset(finalStartPos);
} catch (BadLocationException e) {
finalEndPos += view.getLineOfOffset(finalEndPos);
} catch (BadLocationException e) {
代码示例来源:origin: Vhati/Slipstream-Mod-Manager
private void updateCaretStatus() {
JTextArea currentArea = getCurrentArea();
if ( currentArea == null ) return;
try {
int offset = currentArea.getCaretPosition();
int line = currentArea.getLineOfOffset( offset );
int lineStart = currentArea.getLineStartOffset( line );
int col = offset - lineStart;
int lineCount = currentArea.getLineCount();
statusLbl.setText( String.format( "Line: %4d/%4d Col: %3d", line+1, lineCount, col+1 ) );
}
catch ( BadLocationException e ) {
statusLbl.setText( String.format( "Line: ???/ ??? Col: ???" ) );
}
}
代码示例来源:origin: eu.mihosoft.vrl/vrl
@Override
public void actionPerformed(ActionEvent e) {
JTextArea editor = tRep.getEditor().getEditor();
Document document = editor.getDocument();
int selectionStart = editor.getSelectionStart();
int selectionEnd = editor.getSelectionEnd();
try {
int firstLineOffset = editor.getLineOfOffset(selectionStart);
int lastLineOffset = editor.getLineOfOffset(selectionEnd);
for (int l = firstLineOffset; l <= lastLineOffset; l++) {
int offset = editor.getLineStartOffset(l);
document.insertString(offset, "//", null);
}
} catch (BadLocationException ex) {
Logger.getLogger(GroovyCodeEditorComponent.class.getName()).
log(Level.SEVERE, null, ex);
}
}
}, comment, JComponent.WHEN_FOCUSED);
代码示例来源:origin: stackoverflow.com
try {
lineNo = this.getLineOfOffset(viewToModel)+1;
代码示例来源:origin: eu.mihosoft.vrl/vrl
int caretLinePos = editor.getLineOfOffset(caretPosition);
int firstLineOffset = editor.getLineOfOffset(selectionStart);
int lastLineOffset = editor.getLineOfOffset(selectionEnd);
代码示例来源:origin: net.sf.mmax2/mmax2
try
if (inputTextArea.getLineOfOffset(inputTextArea.getCaretPosition())==inputTextArea.getLineCount()-1)
代码示例来源:origin: stackoverflow.com
JTextArea txt = ...;
int caretOffset = txt.getCaretPosition();
int lineNumber = txt.getLineOfOffset(caretOffset);
int startOffset = txt.getLineStartOffset(lineNumber);
int endOffset = txt.getLineEndOffset(lineNumber);
txt.replaceRange("Replaced Text", startOffset, endOffset);
代码示例来源:origin: net.sf.mmax2/mmax2
if (inputTextArea.getLineOfOffset(inputTextArea.getCaretPosition())==inputTextArea.getLineCount())
代码示例来源:origin: stackoverflow.com
if(viewToModel != -1){
try {
l.setText("line: "+(1+area.getLineOfOffset(viewToModel)));
} catch (BadLocationException e1) {
e1.printStackTrace();
代码示例来源:origin: stackoverflow.com
String text, AttributeSet attrs)
throws BadLocationException {
if(area.getLineCount()<=lineCount && area.getLineOfOffset(area.getCaretPosition())<lineCount)
if(text.contains("\n") && area.getLineCount()<lineCount)
super.replace(fb, offset, length, text, attrs);
代码示例来源:origin: stackoverflow.com
linenum = editArea.getLineOfOffset(caretpos);
代码示例来源:origin: net.sf.squirrel-sql/squirrel-sql
final int line = _logContentsTxt.getLineOfOffset(pos);
final int finalpos = _logContentsTxt.getLineStartOffset(line);
SwingUtilities.invokeAndWait(new Runnable()
代码示例来源:origin: realXuJiang/bigtable-sql
final int line = _logContentsTxt.getLineOfOffset(pos);
final int finalpos = _logContentsTxt.getLineStartOffset(line);
SwingUtilities.invokeAndWait(new Runnable()
代码示例来源:origin: stackoverflow.com
int lineNumber = area.getLineOfOffset(caretOffset);
int startOffset = area.getLineStartOffset(lineNumber);
int endOffset = area.getLineEndOffset(lineNumber);
try {
JTextArea ta = area;
int offset = ta.getLineOfOffset(ta.getCaretPosition());
int start = ta.getLineStartOffset(offset);
int end = ta.getLineEndOffset(offset);
代码示例来源:origin: UNIVALI-LITE/Portugol-Studio
private boolean importaStringArrastada(TransferHandler.TransferSupport support)
{
try
{
String stringArrastada = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
if (stringArrastada.equals(textArea.getSelectedText())) {
if (stringArrastada.isEmpty() || programa == null) {
return false;
}
int linha = textArea.getLineOfOffset(textArea.getSelectionStart()) + 1;
int coluna = textArea.getSelectionStart() - textArea.getLineStartOffset(linha - 1);
int tamanhoDoTexto = textArea.getSelectionEnd() - textArea.getSelectionStart();
ProcuradorDeDeclaracao procuradorDeDeclaracao = new ProcuradorDeDeclaracao(stringArrastada, linha, coluna, tamanhoDoTexto);
programa.getArvoreSintaticaAbstrata().aceitar(procuradorDeDeclaracao);
NoDeclaracao no = procuradorDeDeclaracao.getNoDeclaracao();
if (procuradorDeDeclaracao.encontrou() && !contemNo(no)) {
adicionaNo(no);
}
}
} catch (Exception e) {
return false;
}
return false;
}
代码示例来源:origin: stackoverflow.com
line = textPane.getLineOfOffset(caretPosition);
内容来源于网络,如有侵权,请联系作者删除!