本文整理汇总了Java中javax.swing.text.StyleConstants.setForeground方法的典型用法代码示例。如果您正苦于以下问题:Java StyleConstants.setForeground方法的具体用法?Java StyleConstants.setForeground怎么用?Java StyleConstants.setForeground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleConstants
的用法示例。
在下文中一共展示了StyleConstants.setForeground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例2: getUnusedFieldAttributes
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
private static AttributeSet getUnusedFieldAttributes () {
if (unusedFieldAttributeSet == null) {
SimpleAttributeSet sas = new SimpleAttributeSet ();
StyleConstants.setForeground (sas, new Color (115, 115, 115));
StyleConstants.setBold (sas, true);
unusedFieldAttributeSet = sas;
}
return unusedFieldAttributeSet;
}
示例3: QueryBuilderSqlTextArea
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public QueryBuilderSqlTextArea(QueryBuilder queryBuilder) {
super();
_queryBuilder = queryBuilder;
createSqlTextPopup();
// Get Netbeans-registered EditorKit for SQL content
setEditorKit(CloneableEditorSupport.getEditorKit("text/x-sql"));
if ( SYNTAX_HIGHLIGHT ) {
addKeyListener(this);
}
// set the bold attribute
// colors chosen from :
// http://ui.netbeans.org/docs/hi/annotations/index2.html
StyleConstants.setForeground(keyword,new Color(0,0,153));
StyleConstants.setForeground(schema, new Color(0,111,0));
StyleConstants.setForeground(column,new Color(120,0,0));
// Add support for code completion (comment out, breaks syntax highlighting)
// QueryBuilderSqlCompletion doc = new QueryBuilderSqlCompletion( this, sqlReservedWords);
// this.setDocument(doc);
}
示例4: 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));
}
}
示例5: 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);
}
示例6: appendLog
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
private void appendLog(final String text, final Color color) {
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setForeground(sas, color);
StyledDocument sd = logText.getStyledDocument();
try {
synchronized (this) {
sd.insertString(sd.getLength(), text + "\n", sas);
}
} catch (BadLocationException e) { }
logText.setCaretPosition(sd.getLength());
}
示例7: insert
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public void insert(String str){
StyleConstants.setForeground( attrs, Color.BLACK );
if( str.charAt(0) != ' ' ){
str = " " + str;
}
String str2 = str.replaceAll(";", ";\n");
try {
doc.insertString(offs, str2, attrs);
offs += str2.length();
} catch (BadLocationException e) {
e.printStackTrace();
}
}
示例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;
}
示例9: changeColor
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/**
* Description method that changes the foreground color
* @param document document to be changed
* @return Style for the new document
* @throws BadLocationException
*/
public static Style changeColor(DefaultStyledDocument document) throws BadLocationException {
StyleContext context = new StyleContext();
// build a style
Style style = context.addStyle("test", null);
// set some style properties
StyleConstants.setForeground(style, Color.RED);
return style;
}
示例10: getUnusedParameterAttributes
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
private static AttributeSet getUnusedParameterAttributes () {
if (unusedParameterAttributeSet == null) {
SimpleAttributeSet sas = new SimpleAttributeSet ();
StyleConstants.setForeground (sas, new Color (115, 115, 115));
unusedParameterAttributeSet = sas;
}
return unusedParameterAttributeSet;
}
示例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);
}
示例12: LogAreaOutputStream
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/** Constructs an Out or Err LogAreaOutputStream */
public LogAreaOutputStream(boolean anIsErr) {
isErr = anIsErr;
if(isErr) {
style = addStyle("error", getStyle("default"));
StyleConstants.setForeground(style, Color.red);
} else {
style = addStyle("out", getStyle("default"));
StyleConstants.setForeground(style, Color.black);
}// End if
}
示例13: setColor
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public void setColor(Color c,String s){
try {
StyledDocument doc = jTextPane1.getStyledDocument();
javax.swing.text.Style style = jTextPane1.addStyle("", null);
StyleConstants.setForeground(style, c);
doc.insertString(doc.getLength(), s, style);
jTextPane1.select(0, 10);
jTextPane1.setSelectedTextColor(Color.YELLOW);
} catch (BadLocationException ex) {
System.out.println(ex);
}
}
示例14: setInfo
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/**
* Applies to next append
*/
private void setInfo() {
StyleConstants.setForeground(attr, Color.black);
}
示例15: print
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public static final void print(final String s, final ConsoleStyle style) {
final StyledDocument doc = textPane.getStyledDocument();
if (style == null || style.equals(ConsoleStyle.INFO)) StyleConstants.setForeground(Console.style, Color.BLACK);
else if (style.equals(ConsoleStyle.WARNING)) StyleConstants.setForeground(Console.style, Color.ORANGE);
else StyleConstants.setForeground(Console.style, Color.RED);
try {
doc.insertString(doc.getLength(), s + "\n", Console.style);
} catch (final BadLocationException e) {
}
}