当前位置: 首页>>代码示例>>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;未经允许,请勿转载。