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

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

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

JTextArea.replaceRange介绍

暂无

代码示例

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

curLength+=val.length();
if(val.endsWith(EOL1) || val.endsWith(EOL2)) {
  if(lengths.size()>=maxLines) { textArea.replaceRange("",0,lengths.removeFirst()); }
  lengths.addLast(curLength);
  curLength=0;

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

ta.replaceRange("", ta.getSelectionStart(), ta.getSelectionEnd());

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

JTextArea outputText = new JTextArea(totalPrice);
int offset = outputText.getDocument.getLength() - 1; 
...
price++;
outputText.replaceRange("" + price, offset, offset + 1);

代码示例来源:origin: net.java.openjdk.cacio/cacio-shared

@Override
public void replaceRange(String text, int start, int end) {
  getTextArea().replaceRange(text, start, end);
}

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

package outerr;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.swing.JTextArea;

public class PrintOutErrStream extends ByteArrayOutputStream {

final int maxTextAreaSize = 1000;
private JTextArea textArea;
public PrintOutErrStream(JTextArea textArea) {
  this.textArea = textArea;
}

public void flush() throws IOException {
  synchronized(this) {
    super.flush();
    String outputStr = this.toString();
    super.reset();
    if(textArea.getText().length() > maxTextAreaSize) {
      textArea.replaceRange("", 0, 100);
    }
    textArea.append(outputStr);
  }
}
}

代码示例来源:origin: juliango202/jijimaku

/** MUST BE THE ONLY METHOD THAT TOUCHES textArea. */
public synchronized void run() {
 if (clear) {
  textArea.setText("");
 }
 for (String val : values) {
  curLength += val.length();
  if (val.endsWith(EOL1) || val.endsWith(EOL2)) {
   if (lengths.size() >= maxLines) {
    textArea.replaceRange("", 0, lengths.removeFirst());
   }
   lengths.addLast(curLength);
   curLength = 0;
  }
  textArea.append(val);
 }
 values.clear();
 clear = false;
 queue = true;
}

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

JTextArea ta = new JTextArea("Initial Text");

// Insert some text at the beginning
int pos = 0;
ta.insert("some text", pos);

// Insert some text after the 5th character
pos = 5;
ta.insert("some text", pos);

// Append some text
ta.append("some text");

// Replace the first 3 characters with some text
int start = 0;
int end = 3;
ta.replaceRange("new text", start, end);

// Delete the first 5 characters
start = 0;
end = 5;
ta.replaceRange(null, start, end);

代码示例来源:origin: jagrosh/MusicBot

@Override
public synchronized void run() {
  if(clear) { textArea.setText(""); }
  values.stream().map((val) -> {
    curLength+=val.length();
    return val;
  }).map((val) -> {
    if(val.endsWith(EOL1) || val.endsWith(EOL2)) {
      if(lengths.size()>=maxLines) { textArea.replaceRange("",0,lengths.removeFirst()); }
      lengths.addLast(curLength);
      curLength=0;
    }
    return val;
  }).forEach((val) -> {
    textArea.append(val);
  });
  values.clear();
  clear =false;
  queue =true;
  }
}

代码示例来源:origin: org.simplericity.jettyconsole/jetty-console-core

public void run() {
    text.append(s);
    text.setCaretPosition(text.getDocument().getLength());
    int size = 100000;
    int maxOverflow= 500;
    int overflow = text.getDocument().getLength() - size;
    if (overflow >= maxOverflow) {
      text.replaceRange("", 0, overflow);
    }
  }
});

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

/**
 * Block uncomment the selected text in the given script panel.
 *
 * @param scriptPanel Script panel
 */
private static void blockUncomment(JTextArea scriptPanel) {
  // Recover the index of the start of the selection.
  final int startOffset = scriptPanel.getSelectionStart();
  final int endOffset = scriptPanel.getSelectionEnd();
  // Delete the comment characters.
  scriptPanel.replaceRange("", endOffset - BLOCK_COMMENT_END.length(), endOffset);
  scriptPanel.replaceRange("", startOffset, startOffset + BLOCK_COMMENT_START.length());
  // Select the uncommented selection.
  scriptPanel.setSelectionStart(startOffset);
  scriptPanel.setSelectionEnd(endOffset - BLOCK_COMMENT_START.length()
      - BLOCK_COMMENT_END.length());
}

代码示例来源:origin: IanDarwin/javasrc

/** Format the selection (like unix fmt) */
void format() {
  // "The 50-line text formatter" in 15 lines.
  int col = 0;
  int start = tf.getSelectionStart();
  int end   = tf.getSelectionEnd();
  final String selectedText = tf.getSelectedText();
  if (selectedText == null) {
    JOptionPane.showMessageDialog(this, "Please select text before formatting");
    return;
  }
  StringTokenizer st = new StringTokenizer(selectedText);
  StringBuilder s = new StringBuilder();
  while (st.hasMoreTokens()) {
    String sval = st.nextToken();
    if (col+sval.length() > COLS-7) {
      s.append("\n");
      col = 0;
    }
    s.append(sval).append(' ');
    col+=sval.length()+1;
  }
  tf.replaceRange(s.toString(), start, end);
}

代码示例来源:origin: robo-code/robocode

textArea.replaceRange(null, 0, cutIndex + 1);
textArea.replaceRange(TEXT_TRUNCATED_MSG, 0, getText().indexOf('\n'));

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

JTextArea textArea = new JTextArea("some text");
int start = textArea.getSelectionStart();
int end = textArea.getSelectionEnd();
String replace = textArea.getSelectedText().toUpperCase();
textArea.replaceRange(replace, start, end);

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

int end = textArea.getSelectionEnd();
String replace = textArea.getSelectedText().toUpperCase();
textArea.replaceRange(replace, start, end);

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

/**
   * Uncomment the selected text in the given script panel.
   *
   * @param scriptPanel Script panel
   */
  private static void uncommentSQL(JTextArea scriptPanel, String commentCharacter) {

    final Element root = scriptPanel.getDocument().getDefaultRootElement();

    final int numberOfLastLine = root.getElementIndex(scriptPanel.getSelectionEnd());
    int currentLineNumber = root.getElementIndex(scriptPanel.getSelectionStart());
    while (currentLineNumber <= numberOfLastLine) {
      try {
        int startOffset = root.getElement(currentLineNumber).getStartOffset();
        if (scriptPanel.getText(startOffset, commentCharacter.length()).equals(commentCharacter)) {
          scriptPanel.replaceRange("", startOffset, startOffset + commentCharacter.length());
        }
      } catch (BadLocationException e) {
        LOGGER.warn(I18N.tr("Invalid length or offset when trying to uncomment code."), e);
      }
      currentLineNumber++;
    }
  }
}

代码示例来源:origin: eu.mihosoft.vrl/vrl

uncommentedLines.add(l);
line = line.replaceFirst("\\/\\/", "");
editor.replaceRange(line, offset, editor.getLineEndOffset(l));

相关文章

JTextArea类方法