javax.swing.text.Document.insertString()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(286)

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

Document.insertString介绍

暂无

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

private void buildContentPanel() {
 editorPane = new JEditorPane ();
 editorPane.setContentType("text/rtf");
 editorPane.addKeyListener(new InputListener());
 //    defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes();
 StyleConstants.setFontFamily(defaultAttrSet, "Lucida Sans");
 Document doc = new DefaultStyledDocument();
 editorPane.setDocument(doc);
 try {
  doc.insertString(0, initText, defaultAttrSet);
 } catch (Exception ex) {
  throw new RuntimeException(ex);
 }
 JScrollPane scrollPane = new JScrollPane(editorPane);
 frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
 editorPane.setEditable(true);
}

代码示例来源:origin: stanfordnlp/CoreNLP

private void buildContentPanel() {
 editorPane = new JEditorPane ();
 editorPane.setContentType("text/rtf");
 editorPane.addKeyListener(new InputListener());
 //    defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes();
 StyleConstants.setFontFamily(defaultAttrSet, "Lucinda Sans");
 Document doc = new DefaultStyledDocument();
 editorPane.setDocument(doc);
 try {
  doc.insertString(0, initText, defaultAttrSet);
 } catch (Exception ex) {
  throw new RuntimeException(ex);
 }
 JScrollPane scrollPane = new JScrollPane(editorPane);
 frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
 editorPane.setEditable(true);
}

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

private void newAutocomplete(KeyEvent e)
{
  final JTextComponent input = (JTextComponent)e.getSource();
  final String inputText = input.getText();
  final String nameStart = inputText.substring(0, input.getSelectionStart()) + e.getKeyChar();
  if (findAutocompleteName(nameStart))
  {
    // Assert this.autocompleteName != null
    final String name = this.autocompleteName;
    SwingUtilities.invokeLater(() ->
    {
      try
      {
        input.getDocument().insertString(
          nameStart.length(),
          name.substring(nameStart.length()),
          null);
        input.select(nameStart.length(), name.length());
      }
      catch (BadLocationException ex)
      {
        log.warn("Could not autocomplete name.", ex);
      }
    });
  }
}

代码示例来源:origin: igniterealtime/Openfire

@Override
  public String doInBackground() {
    if (openfired != null) {
      // Get the input stream and read from it
      try (InputStream in = openfired.getInputStream()) {
        int c;
        while ((c = in.read()) != -1) {
          try {
            StyleConstants.setFontFamily(styles, "courier new");
            pane.getDocument().insertString(pane.getDocument().getLength(),
                "" + (char)c, styles);
          }
          catch (BadLocationException e) {
            // Ignore.
          }
        }
      }
      catch (IOException e) {
        e.printStackTrace();
      }
    }
    return "ok";
  }
};

代码示例来源:origin: igniterealtime/Openfire

@Override
  public String doInBackground() {
    if (openfired != null) {
      // Get the input stream and read from it
      try (InputStream in = openfired.getErrorStream()) {
        int c;
        while ((c = in.read()) != -1) {
          try {
            StyleConstants.setForeground(styles, Color.red);
            pane.getDocument().insertString(pane.getDocument().getLength(), "" + (char)c, styles);
          }
          catch (BadLocationException e) {
            // Ignore.
          }
        }
      }
      catch (IOException e) {
        e.printStackTrace();
      }
    }
    return "ok";
  }
};

代码示例来源:origin: stanfordnlp/CoreNLP

public void redraw() {
 String text = editorPane.getText();
 taggedContents = null;
 untaggedContents = null;
 if (!editorPane.getContentType().equals("text/html")) {
  editorPane.setContentType("text/rtf");
  Document doc = editorPane.getDocument();
  try {
   doc.insertString(0, text, defaultAttrSet);
  } catch (Exception e) {
   throw new RuntimeException(e);
  }
  editorPane.revalidate();
  editorPane.repaint();
  editorPane.setEditable(true);
  htmlContents = null;
 } else {
  editorPane.setEditable(false);
  htmlContents = editorPane.getText();
 }
 saveUntagged.setEnabled(false);
 saveTaggedAs.setEnabled(false);
}

代码示例来源:origin: stanfordnlp/CoreNLP

private void clearDocument() {
 editorPane.setContentType("text/rtf");
 Document doc = new DefaultStyledDocument();
 editorPane.setDocument(doc);
 //    defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes();
 //    StyleConstants.setFontFamily(defaultAttrSet, "Lucinda Sans Unicode");
 log.info("attr: "+defaultAttrSet);
 try {
  doc.insertString(0, " ", defaultAttrSet);
 } catch (Exception ex) {
  throw new RuntimeException(ex);
 }
 editorPane.setEditable(true);
 editorPane.revalidate();
 editorPane.repaint();
 saveUntagged.setEnabled(false);
 saveTaggedAs.setEnabled(false);
 taggedContents = null;
 htmlContents = null;
 loadedFile = null;
}

代码示例来源:origin: stanfordnlp/CoreNLP

public void clearDocument() {
 editorPane.setContentType("text/rtf");
 Document doc = new DefaultStyledDocument();
 editorPane.setDocument(doc);
 //    defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes();
 //    StyleConstants.setFontFamily(defaultAttrSet, "Lucinda Sans Unicode");
 log.info("attr: "+defaultAttrSet);
 try {
  doc.insertString(0, " ", defaultAttrSet);
 } catch (Exception ex) {
  throw new RuntimeException(ex);
 }
 editorPane.setEditable(true);
 editorPane.revalidate();
 editorPane.repaint();
 saveUntagged.setEnabled(false);
 saveTaggedAs.setEnabled(false);
 taggedContents = null;
 untaggedContents = null;
 htmlContents = null;
 loadedFile = null;
}

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

private void insertComponent(JComponent comp) {
  try {
    tokenPane.getDocument().insertString(tokenPane.getDocument().getLength(), " ", null);
  } catch (BadLocationException ex1) {
    // Ignore
  }
  try {
    tokenPane.setCaretPosition(tokenPane.getDocument().getLength() - 1);
  } catch (Exception ex) {
    tokenPane.setCaretPosition(0);
  }
  tokenPane.insertComponent(comp);
}

代码示例来源:origin: SonarSource/sonarqube

private void updateMeasures(Component component) {
 measuresEditor.setText("");
 try (CloseableIterator<ScannerReport.Measure> it = reader.readComponentMeasures(component.getRef())) {
  while (it.hasNext()) {
   ScannerReport.Measure measure = it.next();
   measuresEditor.getDocument().insertString(measuresEditor.getDocument().getEndPosition().getOffset(), measure + "\n", null);
  }
 } catch (Exception e) {
  throw new IllegalStateException("Can't read measures for " + getNodeName(component), e);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private void updateSymbols(Component component) {
 symbolEditor.setText("");
 try (CloseableIterator<ScannerReport.Symbol> it = reader.readComponentSymbols(component.getRef())) {
  while (it.hasNext()) {
   ScannerReport.Symbol symbol = it.next();
   symbolEditor.getDocument().insertString(symbolEditor.getDocument().getEndPosition().getOffset(), symbol + "\n", null);
  }
 } catch (Exception e) {
  throw new IllegalStateException("Can't read symbol references for " + getNodeName(component), e);
 }
}

代码示例来源:origin: stanfordnlp/CoreNLP

Document doc = editorPane.getDocument();
try {
 doc.insertString(0, text, defaultAttrSet);
} catch (Exception e) {
 throw new RuntimeException(e);

代码示例来源:origin: SonarSource/sonarqube

private void updateHighlighting(Component component) {
 highlightingEditor.setText("");
 try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(component.getRef())) {
  while (it.hasNext()) {
   ScannerReport.SyntaxHighlightingRule rule = it.next();
   highlightingEditor.getDocument().insertString(highlightingEditor.getDocument().getEndPosition().getOffset(), rule + "\n", null);
  }
 } catch (Exception e) {
  throw new IllegalStateException("Can't read syntax highlighting for " + getNodeName(component), e);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private void updateCoverage(Component component) {
 coverageEditor.setText("");
 try (CloseableIterator<ScannerReport.LineCoverage> it = reader.readComponentCoverage(component.getRef())) {
  while (it.hasNext()) {
   ScannerReport.LineCoverage coverage = it.next();
   coverageEditor.getDocument().insertString(coverageEditor.getDocument().getEndPosition().getOffset(), coverage + "\n", null);
  }
 } catch (Exception e) {
  throw new IllegalStateException("Can't read code coverage for " + getNodeName(component), e);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private void updateScm(Component component) {
 scmEditor.setText("");
 Changesets changesets = reader.readChangesets(component.getRef());
 if (changesets == null) {
  return;
 }
 List<Integer> changesetIndexByLine = changesets.getChangesetIndexByLineList();
 try {
  int index = 0;
  for (Changeset changeset : changesets.getChangesetList()) {
   scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(index) + "\n", null);
   scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), changeset + "\n", null);
   index++;
  }
  scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), "\n", null);
  int line = 1;
  for (Integer idx : changesetIndexByLine) {
   scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(line) + ": " + idx + "\n", null);
   line++;
  }
 } catch (Exception e) {
  throw new IllegalStateException("Can't read SCM for " + getNodeName(component), e);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private void updateIssues(Component component) {
 issuesEditor.setText("");
 try (CloseableIterator<Issue> it = reader.readComponentIssues(component.getRef())) {
  while (it.hasNext()) {
   Issue issue = it.next();
   int offset = issuesEditor.getDocument().getEndPosition().getOffset();
   issuesEditor.getDocument().insertString(offset, issue.toString(), null);
  }
 } catch (Exception e) {
  throw new IllegalStateException("Can't read issues for " + getNodeName(component), e);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private void updateExternalIssues(Component component) {
 externalIssuesEditor.setText("");
 try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(component.getRef())) {
  while (it.hasNext()) {
   ScannerReport.ExternalIssue issue = it.next();
   int offset = externalIssuesEditor.getDocument().getEndPosition().getOffset();
   externalIssuesEditor.getDocument().insertString(offset, issue.toString(), null);
  }
 } catch (Exception e) {
  throw new IllegalStateException("Can't read external issues for " + getNodeName(component), e);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private void updateCpdTextBlocks(Component component) {
 cpdTextBlocksEditor.setText("");
 if (reader.hasCoverage(component.getRef())) {
  try (CloseableIterator<ScannerReport.CpdTextBlock> it = reader.readCpdTextBlocks(component.getRef())) {
   while (it.hasNext()) {
    ScannerReport.CpdTextBlock textBlock = it.next();
    cpdTextBlocksEditor.getDocument().insertString(cpdTextBlocksEditor.getDocument().getEndPosition().getOffset(), textBlock + "\n", null);
   }
  } catch (Exception e) {
   throw new IllegalStateException("Can't read CPD text blocks for " + getNodeName(component), e);
  }
 }
}

代码示例来源:origin: SonarSource/sonarqube

private void updateDuplications(Component component) {
 duplicationEditor.setText("");
 if (reader.hasCoverage(component.getRef())) {
  try (CloseableIterator<ScannerReport.Duplication> it = reader.readComponentDuplications(component.getRef())) {
   while (it.hasNext()) {
    ScannerReport.Duplication dup = it.next();
    duplicationEditor.getDocument().insertString(duplicationEditor.getDocument().getEndPosition().getOffset(), dup + "\n", null);
   }
  } catch (Exception e) {
   throw new IllegalStateException("Can't read duplications for " + getNodeName(component), e);
  }
 }
}

代码示例来源:origin: SonarSource/sonarqube

private void updateSignificantCode(Component component) {
 significantCodeEditor.setText("");
 if (reader.hasCoverage(component.getRef())) {
  try (CloseableIterator<ScannerReport.LineSgnificantCode> it = reader.readComponentSignificantCode(component.getRef())) {
   if (it != null) {
    while (it.hasNext()) {
     ScannerReport.LineSgnificantCode textBlock = it.next();
     significantCodeEditor.getDocument().insertString(significantCodeEditor.getDocument().getEndPosition().getOffset(), textBlock + "\n", null);
    }
   }
  } catch (Exception e) {
   throw new IllegalStateException("Can't read significant code for " + getNodeName(component), e);
  }
 }
}

相关文章