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

x33g5p2x  于2022-01-29 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(168)

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

StyledDocument.getLength介绍

暂无

代码示例

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

  1. public class Main {
  2. public static void main(String[] args) {
  3. JTextPane textPane = new JTextPane();
  4. StyledDocument doc = textPane.getStyledDocument();
  5. Style style = textPane.addStyle("I'm a Style", null);
  6. StyleConstants.setForeground(style, Color.red);
  7. try { doc.insertString(doc.getLength(), "BLAH ",style); }
  8. catch (BadLocationException e){}
  9. StyleConstants.setForeground(style, Color.blue);
  10. try { doc.insertString(doc.getLength(), "BLEH",style); }
  11. catch (BadLocationException e){}
  12. JFrame frame = new JFrame("Test");
  13. frame.getContentPane().add(textPane);
  14. frame.pack();
  15. frame.setVisible(true);
  16. }
  17. }

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

  1. StyledDocument doc = textPane.getStyledDocument();
  2. SimpleAttributeSet center = new SimpleAttributeSet();
  3. StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
  4. doc.setParagraphAttributes(0, doc.getLength(), center, false);

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

  1. JTextPane textPane = new JTextPane();
  2. textPane.setText( "original text" );
  3. StyledDocument doc = textPane.getStyledDocument();
  4. // Define a keyword attribute
  5. SimpleAttributeSet keyWord = new SimpleAttributeSet();
  6. StyleConstants.setForeground(keyWord, Color.RED);
  7. StyleConstants.setBackground(keyWord, Color.YELLOW);
  8. StyleConstants.setBold(keyWord, true);
  9. // Add some text
  10. try
  11. {
  12. doc.insertString(0, "Start of text\n", null );
  13. doc.insertString(doc.getLength(), "\nEnd of text", keyWord );
  14. }
  15. catch(Exception e) { System.out.println(e); }

代码示例来源:origin: RipMeApp/ripme

  1. /**
  2. * Write a line to the Log section of the GUI
  3. *
  4. * @param text the string to log
  5. * @param color the color of the line
  6. */
  7. private void appendLog(final String text, final Color color) {
  8. SimpleAttributeSet sas = new SimpleAttributeSet();
  9. StyleConstants.setForeground(sas, color);
  10. StyledDocument sd = logText.getStyledDocument();
  11. try {
  12. synchronized (this) {
  13. sd.insertString(sd.getLength(), text + "\n", sas);
  14. }
  15. } catch (BadLocationException e) { }
  16. logText.setCaretPosition(sd.getLength());
  17. }

代码示例来源:origin: groovy/groovy-core

  1. public void actionPerformed(ActionEvent ae) {
  2. JTextComponent tComp = (JTextComponent) ae.getSource();
  3. if (tComp.getDocument() instanceof StyledDocument) {
  4. doc = (StyledDocument) tComp.getDocument();
  5. try {
  6. doc.getText(0, doc.getLength(), segment);
  7. }
  8. catch (Exception e) {
  9. // should NEVER reach here
  10. e.printStackTrace();
  11. }
  12. int offset = tComp.getCaretPosition();
  13. int index = findTabLocation(offset);
  14. buffer.delete(0, buffer.length());
  15. buffer.append('\n');
  16. if (index > -1) {
  17. for (int i = 0; i < index + 4; i++) {
  18. buffer.append(' ');
  19. }
  20. }
  21. try {
  22. doc.insertString(offset, buffer.toString(),
  23. doc.getDefaultRootElement().getAttributes());
  24. }
  25. catch (BadLocationException ble) {
  26. ble.printStackTrace();
  27. }
  28. }
  29. }

代码示例来源:origin: kiegroup/optaplanner

  1. private JComponent createNoPlannerFoundTextField() {
  2. String infoMessage = "No planner benchmarks have been found in the benchmarkDirectory ("
  3. + benchmarkAggregator.getBenchmarkDirectory() + ").";
  4. JTextPane textPane = new JTextPane();
  5. textPane.setEditable(false);
  6. textPane.setText(infoMessage);
  7. // center info message
  8. StyledDocument styledDocument = textPane.getStyledDocument();
  9. SimpleAttributeSet center = new SimpleAttributeSet();
  10. StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
  11. StyleConstants.setBold(center, true);
  12. styledDocument.setParagraphAttributes(0, styledDocument.getLength(),
  13. center, false);
  14. return textPane;
  15. }

代码示例来源:origin: apache/pdfbox

  1. void writeIndent(StyledDocument docu) throws BadLocationException
  2. {
  3. if (needIndent)
  4. {
  5. for (int i = 0; i < indent; i++)
  6. {
  7. docu.insertString(docu.getLength(), " ", null);
  8. }
  9. needIndent = false;
  10. }
  11. }
  12. }

代码示例来源:origin: ron190/jsql-injection

  1. /**
  2. * Add a colored string to the textpane, measure prompt at the same time.
  3. * @param string Text to append
  4. * @param color Color of text
  5. * @param isAddingPrompt Should we measure prompt length?
  6. */
  7. private void appendPrompt(String string, Color color, boolean isAddingPrompt) {
  8. try {
  9. StyleConstants.setForeground(this.style, color);
  10. this.styledDocument.insertString(this.styledDocument.getLength(), string, this.style);
  11. if (isAddingPrompt) {
  12. this.prompt += string;
  13. }
  14. } catch (BadLocationException e) {
  15. LOGGER.error(e.getMessage(), e);
  16. }
  17. }

代码示例来源:origin: magefree/mage

  1. private void drawText(java.util.List<String> strings) {
  2. text.setText("");
  3. StyledDocument doc = text.getStyledDocument();
  4. try {
  5. for (String line : strings) {
  6. doc.insertString(doc.getLength(), line + '\n', doc.getStyle("regular"));
  7. }
  8. } catch (BadLocationException ble) {
  9. }
  10. text.setCaretPosition(0);
  11. }

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

  1. StyleConstants.setFontSize(normal, 72);
  2. StyleConstants.setForeground(normal, Color.blue);
  3. doc.insertString(doc.getLength(), "Test", normal);
  4. jtp.setSelectionStart(doc.getLength());
  5. jtp.insertIcon(UIManager.getIcon("OptionPane.warningIcon"));
  6. jtp.setSelectionStart(doc.getLength());
  7. jtp.insertComponent(new JLabel("Label"));
  8. jtp.setSelectionStart(doc.getLength());

代码示例来源:origin: magefree/mage

  1. protected void drawText() {
  2. text.setText("");
  3. StyledDocument doc = text.getStyledDocument();
  4. try {
  5. for (String rule : getRules()) {
  6. doc.insertString(doc.getLength(), rule + '\n', doc.getStyle("small"));
  7. }
  8. } catch (BadLocationException e) {
  9. }
  10. text.setCaretPosition(0);
  11. }

代码示例来源:origin: apache/pdfbox

  1. docu.insertString(docu.getLength(), str + " ", NAME_STYLE);
  2. docu.insertString(docu.getLength(), str + " ", null);
  3. docu.insertString(docu.getLength(), "[ ", null);
  4. for (COSBase elem : (COSArray) obj)
  5. docu.insertString(docu.getLength(), "] ", null);
  6. docu.insertString(docu.getLength(), "(", null);
  7. byte[] bytes = ((COSString) obj).getBytes();
  8. for (byte b : bytes)
  9. docu.insertString(docu.getLength(), str, ESCAPE_STYLE);
  10. docu.insertString(docu.getLength(), str, ESCAPE_STYLE);
  11. docu.insertString(docu.getLength(), str, STRING_STYLE);
  12. docu.insertString(docu.getLength(), ") ", null);
  13. docu.insertString(docu.getLength(), str + " ", NUMBER_STYLE);
  14. docu.insertString(docu.getLength(), "<< ", null);
  15. COSDictionary dict = (COSDictionary) obj;
  16. for (Map.Entry<COSName, COSBase> entry : dict.entrySet())
  17. docu.insertString(docu.getLength(), ">> ", null);

代码示例来源:origin: apache/pdfbox

  1. docu.insertString(docu.getLength(), INLINE_IMAGE_BEGIN + "\n", OPERATOR_STYLE);
  2. COSDictionary dic = op.getImageParameters();
  3. for (COSName key : dic.keySet())
  4. docu.insertString(docu.getLength(), "/" + key.getName() + " ", null);
  5. writeToken(value, docu);
  6. docu.insertString(docu.getLength(), "\n", null);
  7. docu.insertString(docu.getLength(), IMAGE_DATA + "\n", INLINE_IMAGE_STYLE);
  8. docu.insertString(docu.getLength(), imageString, null);
  9. docu.insertString(docu.getLength(), "\n", null);
  10. docu.insertString(docu.getLength(), INLINE_IMAGE_END + "\n", OPERATOR_STYLE);
  11. docu.insertString(docu.getLength(), operator + "\n", OPERATOR_STYLE);

代码示例来源:origin: apache/pdfbox

  1. doc.insertString(doc.getLength(), " " + levelText + " ", levelStyle);
  2. doc.insertString(doc.getLength(), " [" + shortName + "]", nameStyle);
  3. doc.insertString(doc.getLength(), " " + message + "\n", null);
  4. textPane.setCaretPosition(doc.getLength());

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

  1. /**
  2. * Inserts a line break in the specified document.
  3. * @param doc document in which to insert the text.
  4. * @throws BadLocationException thrown if something wrong happened to the document.
  5. */
  6. private static void insertLineBreak(StyledDocument doc) throws BadLocationException {
  7. doc.insertString(doc.getLength(), LINE_BREAK, doc.getStyle(STYLE_NORMAL));
  8. }

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

  1. /**
  2. * Inserts the specified string in the specified document.
  3. * @param doc document in which to insert the text.
  4. * @param string text to insert.
  5. * @throws BadLocationException thrown if something wrong happened to the document.
  6. */
  7. private static void insertNormalString(StyledDocument doc, String string) throws BadLocationException {
  8. doc.insertString(doc.getLength(), string + LINE_BREAK, doc.getStyle(STYLE_NORMAL));
  9. }

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

  1. /**
  2. * Inserts the specified URL in the specified document.
  3. * @param doc document in which to insert the text.
  4. * @param url url to insert.
  5. * @throws BadLocationException thrown if something wrong happened to the document.
  6. */
  7. private static void insertUrl(StyledDocument doc, String url) throws BadLocationException {
  8. doc.insertString(doc.getLength(), " ", doc.getStyle(STYLE_NORMAL));
  9. doc.insertString(doc.getLength(), url + LINE_BREAK, doc.getStyle(STYLE_URL));
  10. }

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

  1. /**
  2. * Inserts the specified string and details in the specified document.
  3. * @param doc document in which to insert the text.
  4. * @param string text to insert.
  5. * @param details details that will be added to the text.
  6. * @throws BadLocationException thrown if something wrong happened to the document.
  7. */
  8. private static void insertDetailedString(StyledDocument doc, String string, String details) throws BadLocationException {
  9. doc.insertString(doc.getLength(), string + " ", doc.getStyle(STYLE_NORMAL));
  10. doc.insertString(doc.getLength(), "(" + details + ")" + LINE_BREAK, doc.getStyle(STYLE_DETAILS));
  11. }

代码示例来源:origin: protegeproject/protege

  1. private void resetStyles(StyledDocument doc) {
  2. doc.setParagraphAttributes(0, doc.getLength(), plainStyle, true);
  3. StyleConstants.setFontSize(fontSizeStyle, getFontSize());
  4. Font f = OWLRendererPreferences.getInstance().getFont();
  5. StyleConstants.setFontFamily(fontSizeStyle, f.getFamily());
  6. doc.setParagraphAttributes(0, doc.getLength(), fontSizeStyle, false);
  7. setupFont();
  8. }

代码示例来源:origin: org.netbeans.api/org-openide-text

  1. public void run() {
  2. try {
  3. addRemoveDocListener(getDoc(), false);
  4. getDoc().remove(0, getDoc().getLength());
  5. addRemoveDocListener(getDoc(), true);
  6. } catch (BadLocationException ble) {
  7. ERR.log(Level.INFO, null, ble);
  8. }
  9. }
  10. }

相关文章