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

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

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

StyledDocument.getStyle介绍

暂无

代码示例

代码示例来源: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: 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: org.swinglabs.swingx/swingx-all

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public Style getStyle(String nm) {
  6. return ((StyledDocument) delegate).getStyle(nm);
  7. }

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

  1. /**
  2. Returns a named style.
  3. @param name The name of the style.
  4. @return The style.
  5. **/
  6. public synchronized Style getStyle (String name)
  7. {
  8. return document_.getStyle (name);
  9. }

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public Style getStyle(String nm) {
  5. return ((StyledDocument) delegate).getStyle(nm);
  6. }

代码示例来源:origin: tmyroadctfig/swingx

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public Style getStyle(String nm) {
  6. return ((StyledDocument) delegate).getStyle(nm);
  7. }

代码示例来源: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 header 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 insertHeader(StyledDocument doc, String string) throws BadLocationException {
  8. doc.insertString(doc.getLength(), string + LINE_BREAK, doc.getStyle(STYLE_HEADER));
  9. }

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

  1. /**
  2. * Redirects the standard output and error streams to the console.
  3. */
  4. public void redirectStandardStreams()
  5. {
  6. System.setOut( new PrintStream( new ConsoleStream( null ) ) );
  7. System.setErr( new PrintStream( new ConsoleStream( _document.getStyle( "error" ) ) ) );
  8. }

代码示例来源:origin: org.integratedmodelling/klab-common

  1. /**
  2. * This is called when the input color is changed so that all input is added with the
  3. * AttributeSet (Style) that has been specified for input.
  4. */
  5. private void setInputAttribute() {
  6. inputControl.setInputAttributeSet(consoleStyledDocument.getStyle(inputColor));
  7. if (!useInlineInput) {
  8. inputArea.setForeground(getStyleColorFromCode(inputColor.charAt(0))); // Foreground
  9. inputArea.setBackground(getStyleColorFromCode(inputColor.charAt(1))); // Background
  10. }
  11. }

代码示例来源:origin: bbuck/DragonConsole

  1. /**
  2. * This is called when the input color is changed so that all input is added
  3. * with the AttributeSet (Style) that has been specified for input.
  4. */
  5. private void setInputAttribute() {
  6. inputControl.setInputAttributeSet(consoleStyledDocument.getStyle(inputColor));
  7. if (!useInlineInput) {
  8. inputArea.setForeground(getStyleColorFromCode(inputColor.charAt(0))); // Foreground
  9. inputArea.setBackground(getStyleColorFromCode(inputColor.charAt(1))); // Background
  10. }
  11. }

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

  1. private void insert(String text, LineStyle style) {
  2. assert ! Log.Dis.cndAsm;
  3. try {
  4. styledDoc.insertString(styledDoc.getLength(),
  5. text,
  6. styledDoc.getStyle(style.toString()));
  7. } catch (BadLocationException ble2) {
  8. System.err.println("View.clear(): Couldn't insert initial text into document.");
  9. }
  10. }

代码示例来源:origin: Vhati/Slipstream-Mod-Manager

  1. public void appendLinkText( String linkURL, String linkTitle ) throws BadLocationException {
  2. if ( browseWorks && linkURL.matches( "^(?:https?|ftp)://.*" ) ) {
  3. SimpleAttributeSet tmpAttr = new SimpleAttributeSet( doc.getStyle( STYLE_HYPERLINK ) );
  4. tmpAttr.addAttribute( ATTR_HYPERLINK_TARGET, linkURL );
  5. doc.insertString( doc.getLength(), linkTitle, tmpAttr );
  6. } else {
  7. doc.insertString( doc.getLength(), linkURL, doc.getStyle( STYLE_REGULAR ) );
  8. }
  9. }

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

  1. private static Style getStyleAtPoint(JTextPane text, Point point) {
  2. int pos = text.viewToModel(point);
  3. StyledDocument doc = text.getStyledDocument();
  4. Element element = doc.getCharacterElement(pos);
  5. AttributeSet addtributes = element.getAttributes();
  6. return doc.getStyle((String) addtributes
  7. .getAttribute(StyleConstants.NameAttribute));
  8. }

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

  1. @Override
  2. public void mouseMoved(MouseEvent e) {
  3. int pos = previewText.viewToModel(e.getPoint());
  4. StyledDocument doc = previewText.getStyledDocument();
  5. Element element = doc.getCharacterElement(pos);
  6. AttributeSet addtributes = element.getAttributes();
  7. Style style = doc.getStyle((String) addtributes
  8. .getAttribute(StyleConstants.NameAttribute));
  9. previewText.setToolTipText(
  10. "Click to change the " + style.getName() + " color");
  11. }
  12. });

代码示例来源:origin: SINTEF-9012/JArduino

  1. public static void print(String id, String data){
  2. try {
  3. StyledDocument doc = screen.getStyledDocument();
  4. doc.insertString(doc.getLength(), formatForPrint(data), doc.getStyle("receive"+id+"Style"));
  5. screen.setCaretPosition(doc.getLength());
  6. } catch (BadLocationException ex) {
  7. ex.printStackTrace();
  8. }
  9. }

代码示例来源:origin: SINTEF-9012/JArduino

  1. public static void print(String id, String data){
  2. try {
  3. StyledDocument doc = screen.getStyledDocument();
  4. doc.insertString(doc.getLength(), formatForPrint(data), doc.getStyle("receive"+id+"Style"));
  5. screen.setCaretPosition(doc.getLength());
  6. } catch (BadLocationException ex) {
  7. ex.printStackTrace();
  8. }
  9. }

相关文章