javax.swing.JTextArea.getLineStartOffset()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(263)

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

JTextArea.getLineStartOffset介绍

暂无

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy

public void actionPerformed(ActionEvent ae) {
  Token token = (Token) ((JComponent) ae.getSource()).getClientProperty("token");
  if (token.getType() == Token.EOF_TYPE) {
    scriptPane.select(0, 0);
    return;
  }
  try {
    int start = scriptPane.getLineStartOffset(token.getLine() - 1) + token.getColumn() - 1;
    scriptPane.select(start, start + token.getText().length());
    scriptPane.requestFocus();
  } catch (BadLocationException ex) {
    // IGNORE
  }
}

代码示例来源:origin: pmd/pmd

@Override
  public void run() {
    try {
      sourceCodeArea.getHighlighter().removeAllHighlights();
      if (node == null) {
        return;
      }
      int startOffset = sourceCodeArea.getLineStartOffset(node.getBeginLine() - 1)
          + node.getBeginColumn() - 1;
      int end = sourceCodeArea.getLineStartOffset(node.getEndLine() - 1) + node.getEndColumn();
      sourceCodeArea.getHighlighter().addHighlight(startOffset, end,
          new DefaultHighlighter.DefaultHighlightPainter(HIGHLIGHT_COLOR));
      sourceCodeArea.moveCaretPosition(startOffset);
    } catch (BadLocationException exc) {
      throw new IllegalStateException(exc.getMessage());
    }
  }
});

代码示例来源:origin: geotools/geotools

writer = new BufferedWriter(new FileWriter(file));
for (int line = 0; line < textArea.getLineCount(); line++) {
  int start = textArea.getLineStartOffset(line);
  int end = textArea.getLineEndOffset(line);
  String lineText = textArea.getText(start, end - start);

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

ta.setCaretPosition(ta.getLineStartOffset(ta.getLineCount() - 1));
} catch (BadLocationException e) {

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

try
  int startIndex = tarea.getLineStartOffset(lineNumber);
  int endIndex = tarea.getLineEndOffset(lineNumber);
  String colour = (String) cbox.getSelectedItem();

代码示例来源:origin: org.apache.jmeter/jorphan

public String[] getTextLines() {
    int numLines = mTextArea.getLineCount();
    String[] lines = new String[numLines];
    for(int i = 0; i < numLines; i++) {
      try {
        int start = mTextArea.getLineStartOffset(i);
        int end = mTextArea.getLineEndOffset(i); // treats last line specially
        if (i == numLines-1) { // Last line
          end++; // Allow for missing terminator
        }
        lines[i]=mTextArea.getText(start, end-start-1);
      } catch (BadLocationException e) { // should not happen
        throw new IllegalStateException("Could not read line "+i,e);
      }
    }
    return lines;
  }
}

代码示例来源: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: 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: com.bitplan.antlr/com.bitplan.antlr

if (component instanceof JTextArea) {
 JTextArea jt = (JTextArea) component;
 position = jt.getLineStartOffset(lineNumber-1);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

private void selectCurrentLine(int x, int y) {
  // This is just temporary placeholder code
  int ln = ta.getLineCount(); 
  if (ln > 0) {
    try {
      selected_area_start = ta.getLineStartOffset(ln);
      selected_area_end = ta.getLineEndOffset(ln);
      ta.select(selected_area_start, selected_area_end);
    } catch (javax.swing.text.BadLocationException e) {
      //selected_area_start = 0;
      //selected_area_end = 0;
    }
  }
}

代码示例来源: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: org.owasp.jbrofuzz/jbrofuzz

/**
   * <p>Write output to the console of the Graphing Panel.</p>
   * 
   * @param input
   */
  public void toConsole(final String input) {

    // Use a FILO for the output to the console, never exceeding 500 lines
    if (console.getLineCount() > 500) {
      try {
        console.select(console.getLineStartOffset(0), console
            .getLineEndOffset(console.getLineCount() - 500));
        console.replaceSelection("...\n");
      } catch (final BadLocationException e) {
        Logger.log("Could not clear the console", 3);
      }
    }

    console.append("> " + input + "\n");
    console.setCaretPosition(console.getText().length());

  }
}

代码示例来源: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: jpos/jPOS

public void run () {
  if (ui.isDestroyed ()) {
    logger.removeListener (this);
    text.setText ("");
    return;
  }
  int lc = text.getLineCount ();
  if (lc > maxLines) {
    try {
      int startOffset = text.getLineStartOffset (maxLines);
      int endOffset = text.getLineEndOffset(lc-1);
      text.getDocument ().remove (startOffset, endOffset-startOffset);
    } catch (BadLocationException ex) {
      text.setText (ex.toString());
    }
  }
}
public LogEvent log (LogEvent evt) {

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

public void actionPerformed(ActionEvent ae){
  Token token = (Token) ((JComponent) ae.getSource()).getClientProperty("token");
  if(token.getType()==Token.EOF_TYPE){
    scriptPane.select(0, 0);
    return;
  }
  try{
    int start = scriptPane.getLineStartOffset(token.getLine()-1)+token.getColumn()-1;
    scriptPane.select(start, start+token.getText().length());
    scriptPane.requestFocus();
  } catch(BadLocationException ex){
    // IGNORE
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal

public void actionPerformed(ActionEvent ae){
  Token token = (Token) ((JComponent) ae.getSource()).getClientProperty("token");
  if(token.getType()==Token.EOF_TYPE){
    scriptPane.select(0, 0);
    return;
  }
  try{
    int start = scriptPane.getLineStartOffset(token.getLine()-1)+token.getColumn()-1;
    scriptPane.select(start, start+token.getText().length());
    scriptPane.requestFocus();
  } catch(BadLocationException ex){
    // IGNORE
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

public void actionPerformed(ActionEvent ae){
  Token token = (Token) ((JComponent) ae.getSource()).getClientProperty("token");
  if(token.getType()==Token.EOF_TYPE){
    scriptPane.select(0, 0);
    return;
  }
  try{
    int start = scriptPane.getLineStartOffset(token.getLine()-1)+token.getColumn()-1;
    scriptPane.select(start, start+token.getText().length());
    scriptPane.requestFocus();
  } catch(BadLocationException ex){
    // IGNORE
  }
}

代码示例来源:origin: org.kohsuke.droovy/groovy

public void actionPerformed(ActionEvent ae){
  Token token = (Token) ((JComponent) ae.getSource()).getClientProperty("token");
  if(token.getType()==Token.EOF_TYPE){
    scriptPane.select(0, 0);
    return;
  }
  try{
    int start = scriptPane.getLineStartOffset(token.getLine()-1)+token.getColumn()-1;
    scriptPane.select(start, start+token.getText().length());
    scriptPane.requestFocus();
  } catch(BadLocationException ex){
    // IGNORE
  }
}

代码示例来源:origin: net.sourceforge.pmd/pmd-core

@Override
  public void run() {
    try {
      sourceCodeArea.getHighlighter().removeAllHighlights();
      if (node == null) {
        return;
      }
      int startOffset = sourceCodeArea.getLineStartOffset(node.getBeginLine() - 1)
          + node.getBeginColumn() - 1;
      int end = sourceCodeArea.getLineStartOffset(node.getEndLine() - 1) + node.getEndColumn();
      sourceCodeArea.getHighlighter().addHighlight(startOffset, end,
          new DefaultHighlighter.DefaultHighlightPainter(HIGHLIGHT_COLOR));
      sourceCodeArea.moveCaretPosition(startOffset);
    } catch (BadLocationException exc) {
      throw new IllegalStateException(exc.getMessage());
    }
  }
});

代码示例来源: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;
}

相关文章

JTextArea类方法