當前位置: 首頁>>代碼示例>>Java>>正文


Java StyleConstants.setFontFamily方法代碼示例

本文整理匯總了Java中javax.swing.text.StyleConstants.setFontFamily方法的典型用法代碼示例。如果您正苦於以下問題:Java StyleConstants.setFontFamily方法的具體用法?Java StyleConstants.setFontFamily怎麽用?Java StyleConstants.setFontFamily使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.StyleConstants的用法示例。


在下文中一共展示了StyleConstants.setFontFamily方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: publish

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
@Override
public void publish(final LogRecord record) {
  StyledDocument doc = textPane.getStyledDocument();
  SimpleAttributeSet keyWord = new SimpleAttributeSet();
  StyleConstants.setForeground(keyWord, getColor(record.getLevel()));
  StyleConstants.setBold(keyWord, true);
  StyleConstants.setFontSize(keyWord, 12);
  StyleConstants.setFontFamily(keyWord, CONSOLE_FONT);

  SimpleAttributeSet text = new SimpleAttributeSet();
  StyleConstants.setForeground(text, getColor(record.getLevel()));
  StyleConstants.setFontFamily(text, CONSOLE_FONT);
  try {
    doc.insertString(doc.getLength(), String.format("%1$-10s", record.getLevel()), keyWord);
    if (record.getParameters() != null) {
      doc.insertString(doc.getLength(), MessageFormat.format(record.getMessage(), record.getParameters()), text);
    } else {
      doc.insertString(doc.getLength(), record.getMessage(), text);
    }

    doc.insertString(doc.getLength(), "\n", text);
  } catch (BadLocationException e) {
  }

  textPane.setCaretPosition(doc.getLength());
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:27,代碼來源:ConsoleLogHandler.java

示例2: initialize

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/**
 * Initialises this
 */
private void initialize() {
	
	black = new SimpleAttributeSet();
    StyleConstants.setForeground(black, Color.black);
    StyleConstants.setFontFamily(black, "Courier");
    StyleConstants.setFontSize(black, 11);
    red = new SimpleAttributeSet();
    StyleConstants.setForeground(red, Color.red);
    StyleConstants.setFontFamily(red, "Courier");
    StyleConstants.setFontSize(red, 11);
    
    this.setLayout(new BorderLayout());
	this.setSize(400,100);
	this.setPreferredSize(new Dimension(400, 100));
    this.add(getJScrollPane(),BorderLayout.CENTER);
	
	if (this.isLocalConsole()==true) {
		// --- listen to local Out/Err-Output ---------
		SysOutBoard.setSysOutScanner(new SysOutScanner(this));
	}
	
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:26,代碼來源:JPanelConsole.java

示例3: setFontName

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/** Set the font name. */
public void setFontName(String fontName) {
	if (log == null)
		return;
	this.fontName = fontName;
	log.setFont(new Font(fontName, Font.PLAIN, fontSize));
	StyleConstants.setFontFamily(styleRegular, fontName);
	StyleConstants.setFontFamily(styleBold, fontName);
	StyleConstants.setFontFamily(styleRed, fontName);
	StyleConstants.setFontSize(styleRegular, fontSize);
	StyleConstants.setFontSize(styleBold, fontSize);
	StyleConstants.setFontSize(styleRed, fontSize);
	// Changes all existing text
	StyledDocument doc = log.getStyledDocument();
	Style temp = doc.addStyle("temp", null);
	StyleConstants.setFontFamily(temp, fontName);
	StyleConstants.setFontSize(temp, fontSize);
	doc.setCharacterAttributes(0, doc.getLength(), temp, false);
	// Changes all existing hyperlinks
	Font newFont = new Font(fontName, Font.BOLD, fontSize);
	for (JLabel link : links) {
		link.setFont(newFont);
	}
}
 
開發者ID:AlloyTools,項目名稱:org.alloytools.alloy,代碼行數:25,代碼來源:SwingLogPanel.java

示例4: do_setFont

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/** Changes the font and tabsize for the document. */
public final void do_setFont(String fontName, int fontSize, int tabSize) {
   if (tabSize < 1) tabSize = 1; else if (tabSize > 100) tabSize = 100;
   if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize) return;
   this.font = fontName;
   this.fontSize = fontSize;
   this.tabSize = tabSize;
   for(MutableAttributeSet s: all) { StyleConstants.setFontFamily(s, fontName);  StyleConstants.setFontSize(s, fontSize); }
   do_reapplyAll();
   BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); // this is used to derive the tab width
   int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
   TabStop[] pos = new TabStop[100];
   for(int i=0; i<100; i++) { pos[i] = new TabStop(i*gap + gap); }
   StyleConstants.setTabSet(tabset, new TabSet(pos));
   setParagraphAttributes(0, getLength(), tabset, false);
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:17,代碼來源:OurSyntaxDocument.java

示例5: setFontName

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/** Set the font name. */
public void setFontName(String fontName) {
    if (log==null) return;
    this.fontName = fontName;
    log.setFont(new Font(fontName, Font.PLAIN, fontSize));
    StyleConstants.setFontFamily(styleRegular, fontName);
    StyleConstants.setFontFamily(styleBold, fontName);
    StyleConstants.setFontFamily(styleRed, fontName);
    StyleConstants.setFontSize(styleRegular, fontSize);
    StyleConstants.setFontSize(styleBold, fontSize);
    StyleConstants.setFontSize(styleRed, fontSize);
    // Changes all existing text
    StyledDocument doc=log.getStyledDocument();
    Style temp=doc.addStyle("temp", null);
    StyleConstants.setFontFamily(temp, fontName);
    StyleConstants.setFontSize(temp, fontSize);
    doc.setCharacterAttributes(0, doc.getLength(), temp, false);
    // Changes all existing hyperlinks
    Font newFont = new Font(fontName, Font.BOLD, fontSize);
    for(JLabel link: links) { link.setFont(newFont); }
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:22,代碼來源:SwingLogPanel.java

示例6: DocumentHandler

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/**
 * Constructor
 *
 * @param textPane
 */
public DocumentHandler(JTextPane textPane) {
    this.textPane = textPane;
    setFormatter(new RecordFormatter());

    StyledDocument document = (StyledDocument) this.textPane.getDocument();

    infoStyle = document.addStyle("INFO", null);
    StyleConstants.setFontFamily(infoStyle, "Monospaced");
    StyleConstants.setBackground(infoStyle, Color.white);
    StyleConstants.setForeground(infoStyle, Color.blue);

    severStyle = document.addStyle("SEVER", null);
    StyleConstants.setFontFamily(severStyle, "Monospaced");
    StyleConstants.setBackground(severStyle, Color.white);
    StyleConstants.setForeground(severStyle, Color.red);
}
 
開發者ID:YcheCourseProject,項目名稱:DIA-Umpire-Maven,代碼行數:22,代碼來源:DocumentHandler.java

示例7: addStyles

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
private void addStyles() {
	Style s;
	Style def = StyleContext.getDefaultStyleContext().getStyle(
			StyleContext.DEFAULT_STYLE);

	Style regular = doc.addStyle("regular", def);
	// StyleConstants.setForeground(regular, Color.BLACK);
	StyleConstants.setFontFamily(regular, "SansSerif");
	// StyleConstants.setFontSize(regular, 10)
	// StyleConstants.setBold(regular, true);
	// StyleConstants.setItalic(regular, true);
	// StyleConstants.setAlignment(regular, StyleConstants.ALIGN_CENTER);

	s = doc.addStyle("debug", regular);
	StyleConstants.setForeground(s, Color.ORANGE);
	StyleConstants.setFontFamily(s, "SansSerif");
	// StyleConstants.setFontSize(s, 10)
	// StyleConstants.setBold(s, true);
	// StyleConstants.setItalic(s, true);
	// StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);

	s = doc.addStyle("warn", regular);
	StyleConstants.setForeground(s, Color.RED);
	StyleConstants.setFontFamily(s, "SansSerif");
	// StyleConstants.setFontSize(s, 10)
	StyleConstants.setBold(s, true);
	// StyleConstants.setItalic(s, true);
	// StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);

	s = doc.addStyle("notify", regular);
	StyleConstants.setForeground(s, Color.GREEN);
	StyleConstants.setFontFamily(s, "SansSerif");
	// StyleConstants.setFontSize(s, 10)
	StyleConstants.setBold(s, true);
	// StyleConstants.setItalic(s, true);
	// StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:38,代碼來源:ConsolePanel.java

示例8: style

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/**
 * Helper method that construct a mutable style with the given font name,
 * font size, boldness, color, and left indentation.
 */
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, Color color, int leftIndent) {
	MutableAttributeSet s = new SimpleAttributeSet();
	StyleConstants.setFontFamily(s, fontName);
	StyleConstants.setFontSize(s, fontSize);
	StyleConstants.setBold(s, boldness);
	StyleConstants.setForeground(s, color);
	StyleConstants.setLeftIndent(s, leftIndent);
	return s;
}
 
開發者ID:AlloyTools,項目名稱:org.alloytools.alloy,代碼行數:14,代碼來源:OurConsole.java

示例9: do_setFont

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/** Changes the font and tabsize for the document. */
public final void do_setFont(String fontName, int fontSize, int tabSize) {
	if (tabSize < 1)
		tabSize = 1;
	else if (tabSize > 100)
		tabSize = 100;
	if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize)
		return;
	this.font = fontName;
	this.fontSize = fontSize;
	this.tabSize = tabSize;
	for (MutableAttributeSet s : all) {
		StyleConstants.setFontFamily(s, fontName);
		StyleConstants.setFontSize(s, fontSize);
	}
	do_reapplyAll();
	BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); // this
																				// is
																				// used
																				// to
																				// derive
																				// the
																				// tab
																				// width
	int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
	TabStop[] pos = new TabStop[100];
	for (int i = 0; i < 100; i++) {
		pos[i] = new TabStop(i * gap + gap);
	}
	StyleConstants.setTabSet(tabset, new TabSet(pos));
	setParagraphAttributes(0, getLength(), tabset, false);
}
 
開發者ID:AlloyTools,項目名稱:org.alloytools.alloy,代碼行數:33,代碼來源:OurSyntaxDocument.java

示例10: getFontAttribute

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/**
 * 獲取某種字體
 * @param name 字體名稱
 * @param size 字體大小
 * @param color 字體顏色
 * @param bold 是否加粗
 * @param underline 是否加下劃線
 * @return 返回獲取的字體
 */
public static SimpleAttributeSet getFontAttribute(String name, int size, Color color,
		boolean bold, boolean underline)
{
	SimpleAttributeSet attribute = new SimpleAttributeSet();
	StyleConstants.setFontFamily(attribute, name);
	StyleConstants.setFontSize(attribute, size);
	StyleConstants.setForeground(attribute, color);
	StyleConstants.setBold(attribute, bold);
	StyleConstants.setUnderline(attribute, underline);
	return attribute;
}
 
開發者ID:sxei,項目名稱:myqq,代碼行數:21,代碼來源:MyTextPane.java

示例11: initStyleContext

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
public static void initStyleContext(Font font) {
    Style defaultStyle = StyleContext.getDefaultStyleContext()
        .getStyle(StyleContext.DEFAULT_STYLE);

    STYLE_CONTEXT = new StyleContext();
    Style regular = STYLE_CONTEXT.addStyle("regular", defaultStyle);
    StyleConstants.setFontFamily(regular, font.getFamily());
    StyleConstants.setFontSize(regular, font.getSize());

    Style buttonStyle = STYLE_CONTEXT.addStyle("button", regular);
    StyleConstants.setForeground(buttonStyle, LINK_COLOR);

    Style right = STYLE_CONTEXT.addStyle("right", regular);
    StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:16,代碼來源:Utility.java

示例12: style

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/** Helper method that construct a mutable style with the given font name, font size, boldness, color, and left indentation. */
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, Color color, int leftIndent) {
   MutableAttributeSet s = new SimpleAttributeSet();
   StyleConstants.setFontFamily(s, fontName);
   StyleConstants.setFontSize(s, fontSize);
   StyleConstants.setBold(s, boldness);
   StyleConstants.setForeground(s, color);
   StyleConstants.setLeftIndent(s, leftIndent);
   return s;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:11,代碼來源:OurConsole.java

示例13: createStyles

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
static void createStyles() {
    styles = new StyleContext();
    doc = new DefaultStyledDocument(styles);
    contentAttributes = new HashMap<>();

    // no attributes defined
    Style s = styles.addStyle(null, null);
    contentAttributes.put("none", s);

    Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);

    Style heading = styles.addStyle("heading", def);
    StyleConstants.setFontFamily(heading, "SansSerif");
    StyleConstants.setBold(heading, true);
    StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(heading, 10);
    StyleConstants.setSpaceBelow(heading, 10);
    StyleConstants.setFontSize(heading, 18);

    // Title
    Style sty = styles.addStyle("title", heading);
    StyleConstants.setFontSize(sty, 32);

    // author
    sty = styles.addStyle("author", heading);
    StyleConstants.setItalic(sty, true);
    StyleConstants.setSpaceBelow(sty, 25);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:JViewPortBackingStoreImageTest.java

示例14: appendLineForBatch

import javax.swing.text.StyleConstants; //導入方法依賴的package包/類
/**
 * Stores the given {@link String} line for the next batch update. If the number of elements
 * awaiting batch update are >= maxRows, will discard the oldest element. Call
 * {@link #executeBatch(int)} or {@link #executeBatchAppend()} to execute the batch update.
 * <p>
 * <strong>Attention:</strong> Every {@link String} is considered as one line so a line
 * separator will be added into the document after it.
 * </p>
 * <p>
 * This method is thread safe.
 * </p>
 *
 * @param str
 *            the {@link String} to add to the document.
 * @param a
 *            the style formatting settings
 */
public void appendLineForBatch(String str, SimpleAttributeSet a) {
	if (str == null || str.isEmpty()) {
		throw new IllegalArgumentException("str must not be null or empty!");
	}
	if (!str.endsWith(System.lineSeparator())) {
		str += System.lineSeparator();
	}

	char[] txt = str.toCharArray();
	a = a != null ? (SimpleAttributeSet) a.copyAttributes() : new SimpleAttributeSet();
	// set font family if not set
	if (a.getAttribute(StyleConstants.FontFamily) == null) {
		StyleConstants.setFontFamily(a, DEFAULT_FONT_FAMILY);
	}

	synchronized (LOCK) {
		// make sure batch size does not exceed maxRows *3 (*3 because we add the str and 2 line
		// separator tags)
		if (maxRows > 0) {
			while (listToInsert.size() >= maxRows * 3) {
				// remove element itself and both line separator elements)
				// we start at the beginning because we discard oldest first
				listToInsert.removeFirst();
				listToInsert.removeFirst();
				listToInsert.removeFirst();
				lineLength.removeFirst();
			}
		}

		// close previous paragraph tag, start new one, add text
		// yes the order is correct; no you cannot change to start/text/end
		// if you do, linebreaks get messed up
		listToInsert.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.EndTagType));
		listToInsert.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.StartTagType));
		listToInsert.add(new ElementSpec(a, ElementSpec.ContentType, txt, 0, txt.length));

		// store length of each row we add
		lineLength.add(txt.length);
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:58,代碼來源:ExtendedStyledDocument.java


注:本文中的javax.swing.text.StyleConstants.setFontFamily方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。