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

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

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

JTextArea.getLineCount介绍

暂无

代码示例

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

for (int line = 0; line < textArea.getLineCount(); line++) {
  int start = textArea.getLineStartOffset(line);
  int end = textArea.getLineEndOffset(line);

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

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

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

void read(Reader reader) throws IOException {
  // Feed the file's contents to text area
  textArea.read(reader, null);
  // If there are more than one lines, there is a line separator
  lineSeparatorExists = textArea.getLineCount() > 1;
  // Move cursor to the top
  textArea.setCaretPosition(0);
}

代码示例来源:origin: sensepost/yeti

public void addDebug(String message) {
  //System.out.println ("Free memory : " + Runtime.getRuntime().freeMemory() );
  if (this.txtDebug.getLineCount() > 500) {
    //this.txtDebug.setText("Info: Trunc...\n");
  }
  this.txtDebug.append("Debug: " + message + "\n");
  this.txtDebug.setCaretPosition(this.txtDebug.getDocument().getLength() - 1);
}

代码示例来源:origin: fr.inria.wimmics/kggui

public int getLineNumber() {
  return sparqlQueryEditor.getTextAreaLines().getLineCount();
}

代码示例来源:origin: Wimmics/corese

public int getLineNumber() {
  return sparqlQueryEditor.getTextAreaLines().getLineCount();
}

代码示例来源:origin: org.geotools/gt-swing

/**
 * Appends the given text to that displayed. No additional newlines
 * are added after the text.
 * 
 * @param text the text to append
 * @param indent indent width as number of spaces
 */
private void append(final String text, final int indent) {
  int startLine = textArea.getLineCount();
  String appendText;
  if (indent > 0) {
    char[] c = new char[indent];
    Arrays.fill(c, ' ');
    String pad = String.valueOf(c);
    appendText = pad + text.replaceAll("\\n", "\n" + pad);
  } else {
    appendText = text;
  }
  textArea.append(appendText);
  textArea.setCaretPosition(textArea.getDocument().getLength());
}

代码示例来源:origin: com.itextpdf/itext-rups

public void run() {
    Document doc = textArea.getDocument();
    if (textArea.getLineCount() >= MAX_LINES) {
      String backupString = "";
      try {
        backupString = textArea.getText(
            Math.max(textArea.getDocument().getLength() - BACKUP_SIZE, 0),
            Math.min(textArea.getDocument().getLength(), BACKUP_SIZE));
      } catch (BadLocationException ignored) {
      }
      textArea.setText(backupString + "\n...too many output\n");
    }
    textArea.append(msg);
    textArea.setCaretPosition(textArea.getDocument().getLength());
  }
});

代码示例来源: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 void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
  if (address.getLineCount() < 5 || !string.contains("\n"))
    super.insertString(fb, offset, string, attr);
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
  if (address.getLineCount() < 5 || !text.contains("\n"))
    super.replace(fb, offset, length, text, attrs);

代码示例来源:origin: java-deobfuscator/deobfuscator-gui

@Override
  public void write(int b) throws IOException 
  {
    console.append(String.valueOf((char)b));
    if(shouldLimitLines.isSelected() && console.getLineCount() > 100)
    {
      try
      {
        console.replaceRange("", 0, console.getLineEndOffset(0));
      }catch(Exception 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: 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: apache/axis2-java

private void setParameter(ParameterObj obj){
  int position = desArea.getCaretPosition();
  System.out.println(desArea.getLineCount());
  System.out.println(desArea.getCaretPosition());
  String str = "      <parameter name=\"" + obj.getName() + "\" locked=\"false\">"
            + obj.getValue() +
            "</parameter>\n";
  desArea.insert(str, position + 1);
}
private void setModule(String module){

代码示例来源:origin: sundapeng/FinalSpeed

public void trunkTextArea(JTextArea txtWin){
  int numLinesToTrunk = txtWin.getLineCount() - SCROLL_BUFFER_SIZE;
  if(numLinesToTrunk > 0)
  {
    try
    {
      int posOfLastLineToTrunk = txtWin.getLineEndOffset(numLinesToTrunk - 1);
      txtWin.replaceRange("",0,posOfLastLineToTrunk);
    }
    catch (BadLocationException ex) {
      ex.printStackTrace();
    }
  }
}

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

final int SCROLL_BUFFER_SIZE = 100;
public void trunkTextArea(JTextArea txtWin)
{
  int numLinesToTrunk = txtWin.getLineCount() - SCROLL_BUFFER_SIZE;
  if(numLinesToTrunk > 0)
  {
    try
    {
      int posOfLastLineToTrunk = txtWin.getLineEndOffset(numLinesToTrunk - 1);
      txtWin.replaceRange("",0,posOfLastLineToTrunk);
    }
    catch (BadLocationException ex) {
      ex.printStackTrace();
    }
  }
}

代码示例来源:origin: net.sf.mmax2/mmax2

if (inputTextArea.getLineOfOffset(inputTextArea.getCaretPosition())==inputTextArea.getLineCount())

代码示例来源: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);
    else if(!text.contains("\n"))

代码示例来源: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) {

相关文章

JTextArea类方法