本文整理匯總了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) {
}
}