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


Java StyleContext.addAttribute方法代碼示例

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


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

示例1: createSearchPanel

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
private Component createSearchPanel() {
    StyleContext styleContent = StyleContext.getDefaultStyleContext();

    AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);

    AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);

    searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
    searchPanel.hide();

    return searchPanel.getComponent();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:18,代碼來源:OutputPanel.java

示例2: appendToPane

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
private void appendToPane(JTextPane tp, String msg, MessageType t)
{
    boolean scrollToBottom = scrollPane.getVerticalScrollBar().getValue() == scrollPane.getVerticalScrollBar().getMaximum();
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = SimpleAttributeSet.EMPTY;

    MessageStyle ms = theme.getStyle(t);

    aset = sc.addAttribute(aset, StyleConstants.Foreground, ms.getForeground() == null ? tp.getForeground() : ms.getForeground());
    aset = sc.addAttribute(aset, StyleConstants.Background, ms.getBackground() == null ? tp.getBackground() : ms.getBackground());
    aset = sc.addAttribute(aset, StyleConstants.Bold, ms.isBold());
    aset = sc.addAttribute(aset, StyleConstants.Italic, ms.isItalic());
    aset = sc.addAttribute(aset, StyleConstants.Underline, ms.isUnderlined());

    StyledDocument sd = tp.getStyledDocument();
    try
    {
        sd.insertString(sd.getLength(), msg, aset);
    }
    catch(BadLocationException e)
    {
        e.printStackTrace();
    }

    if(scrollToBottom)
    {
        scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum());
    }
}
 
開發者ID:utybo,項目名稱:NetClean,代碼行數:30,代碼來源:ClientGUI.java

示例3: appendToPane

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
/**
 * Appends stylized text to a textpane
 * 
 * @param tp
 *            Textpane
 * @param msg
 *            Message to append. Will automatically place newline at end.
 * @param c
 *            Color of text.
 */
public static void appendToPane(JTextPane tp, String msg, Color c) {
	StyleContext sc = StyleContext.getDefaultStyleContext();
	AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

	int len = tp.getDocument().getLength(); // same value as
	// getText().length();
	tp.setCaretPosition(len); // place caret at the end (with no selection)

	StyledDocument doc = tp.getStyledDocument();
	try {
		doc.insertString(doc.getLength(), msg + "\n", aset);
	} catch (BadLocationException e) {
		e.printStackTrace();
	}
}
 
開發者ID:Mgamerz,項目名稱:me3modmanager,代碼行數:26,代碼來源:ResourceUtils.java

示例4: append

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
@Override
public void append(String str, Color c) {

	StyleContext sc = StyleContext.getDefaultStyleContext();
	AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

	aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Sans");
	aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

	/*
	 * int len = area.getDocument().getLength(); area.setCaretPosition(len);
	 * area.setCharacterAttributes(aset, false); area.replaceSelection(str);
	 */

	DefaultStyledDocument document = (DefaultStyledDocument) area.getDocument();
	try {
		if (area.getText().length() < 3)
			area.setText("");
		// document.insertString(0, str, aset);
		// else
		document.insertString(document.getEndPosition().getOffset() - 1, str, aset);
	} catch (BadLocationException e) {}

}
 
開發者ID:tobiasschulz,項目名稱:voipcall,代碼行數:25,代碼來源:JTextPaneMessageOutput.java

示例5: setupTabStops

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
private void setupTabStops() {
	// Ugly piece of code; needed because default tab indentation is too
	// big.
	StyleContext sc = StyleContext.getDefaultStyleContext();

	Toolkit t = Toolkit.getDefaultToolkit();
	FontMetrics fm = t.getFontMetrics(new Font("Courier", Font.PLAIN, 14));
	int cw = fm.stringWidth("    ");

	final TabStop[] tabStops = new TabStop[60];
	for (int i = 0; i < tabStops.length; i++)
		tabStops[i] = new TabStop((i + 1) * cw);

	TabSet tabs = new TabSet(tabStops);
	AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY,
			StyleConstants.TabSet, tabs);

	pane.setParagraphAttributes(paraSet, false);
}
 
開發者ID:goblindegook,項目名稱:Koopa,代碼行數:20,代碼來源:GrammarView.java

示例6: appendToLog

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
/**
 * Appends a message to the logging area.
 * 
 * @param message
 *            Message to add
 * @param color
 *            Color of the message
 */
private void appendToLog(final String message, final Color color) {
	final StyleContext sc = StyleContext.getDefaultStyleContext();
	AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);

	aset = sc.addAttribute(aset, StyleConstants.FontFamily, DEFAULT_FONT);
	aset = sc.addAttribute(aset, StyleConstants.Alignment, Integer.valueOf(StyleConstants.ALIGN_JUSTIFIED));

	final int len = this.mLogArea.getDocument().getLength();
	this.mLogArea.setCaretPosition(len);
	this.mLogArea.setCharacterAttributes(aset, false);
	this.mLogArea.setEditable(true);
	this.mLogArea.replaceSelection(message);
	this.mLogArea.setEditable(false);
}
 
開發者ID:ZabuzaW,項目名稱:KivaBot,代碼行數:23,代碼來源:MainFrameView.java

示例7: append

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
public void append(Color c, String s) {
    if (c == null)
        c = defaultColor;
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet as = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
    try {
        getDocument().insertString(getDocument().getLength(), s, as);
    } catch (BadLocationException e) {            
    }
}
 
開發者ID:nickrfer,項目名稱:code-sentinel,代碼行數:11,代碼來源:MASConsoleColorGUI.java

示例8: append

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
public void append(Color c, String s) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    int len = getDocument().getLength();
    setCaretPosition(len);
    setCharacterAttributes(aset, false);
    replaceSelection(s);
}
 
開發者ID:fcpauldiaz,項目名稱:Compilador,代碼行數:10,代碼來源:ColorPane.java

示例9: append

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
public void append(Color c, String s) {
    if (c == null)
        c = defaultColor;
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet as = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
    try {
        getDocument().insertString(getDocument().getLength(), s, as);
    } catch (BadLocationException e) {
    }
}
 
開發者ID:jason-lang,項目名稱:jason,代碼行數:11,代碼來源:MASConsoleColorGUI.java

示例10: append

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
public void append(Color color, String s) {
  StyleContext styleContext = StyleContext.getDefaultStyleContext();
  AttributeSet attributeSet = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
  int len = getDocument().getLength();
  setCaretPosition(len);
  setCharacterAttributes(attributeSet, false);
  replaceSelection(s);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:9,代碼來源:IpnbErrorPanel.java

示例11: setTabSize

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
private void setTabSize(int size) {
		 	TabStop[] tabs = new TabStop[1];
	        tabs[0] = new TabStop(size, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
//	        tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
//	        tabs[2] = new TabStop(200, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE);
//	        tabs[3] = new TabStop(300, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE);
	        TabSet tabset = new TabSet(tabs);

	        StyleContext sc = StyleContext.getDefaultStyleContext();
	        AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
	        StyleConstants.TabSet, tabset);
	        textPane.setParagraphAttributes(aset, false);
	}
 
開發者ID:Emd4600,項目名稱:SporeModder,代碼行數:14,代碼來源:TextFileView.java

示例12: appendToPane

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
private void appendToPane(String msg, Color c)
{
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
    aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

    int len = textPane.getDocument().getLength();
    textPane.setCaretPosition(len);
    textPane.setCharacterAttributes(aset, false);
    textPane.replaceSelection(msg);
}
 
開發者ID:Emd4600,項目名稱:SporeModder,代碼行數:14,代碼來源:ConsoleDialog.java

示例13: append

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
private void append (String mensaje, Color color) {
    StyleContext styleContext = StyleContext.getDefaultStyleContext();
    AttributeSet attributeSet = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);

    attributeSet = styleContext.addAttribute(attributeSet, StyleConstants.FontFamily, "Lucida Console");
    attributeSet = styleContext.addAttribute(attributeSet, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

    int longitud = historial.getDocument().getLength();
    historial.setCaretPosition(longitud);
    historial.setCharacterAttributes(attributeSet, false);
    historial.replaceSelection(mensaje);
}
 
開發者ID:fblupi,項目名稱:grado_informatica-DSD,代碼行數:13,代碼來源:ChatView.java

示例14: appendError

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
public void appendError(String s) {
	StyleContext sc = StyleContext.getDefaultStyleContext();
	AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground,
			Color.RED);

	textField.setCharacterAttributes(aset, false);
	textField.replaceSelection(s);
	int len = doc.getLength();
	textField.setCaretPosition(len);
}
 
開發者ID:jdmp,項目名稱:java-data-mining-package,代碼行數:11,代碼來源:CommandWindow.java

示例15: appendText

import javax.swing.text.StyleContext; //導入方法依賴的package包/類
public void appendText(String s) {
	StyleContext sc = StyleContext.getDefaultStyleContext();
	AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground,
			Color.BLACK);

	textField.setCharacterAttributes(aset, false);
	textField.replaceSelection(s);
	int len = doc.getLength();
	textField.setCaretPosition(len);
}
 
開發者ID:jdmp,項目名稱:java-data-mining-package,代碼行數:11,代碼來源:CommandWindow.java


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