本文整理汇总了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());
}
示例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));
}
}
示例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);
}
}
示例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);
}
示例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); }
}
示例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);
}
示例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);
}
示例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: 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);
}
示例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;
}
示例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: 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;
}
示例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);
}
示例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);
}
}