本文整理汇总了Java中javax.swing.text.StyleConstants.setFontSize方法的典型用法代码示例。如果您正苦于以下问题:Java StyleConstants.setFontSize方法的具体用法?Java StyleConstants.setFontSize怎么用?Java StyleConstants.setFontSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleConstants
的用法示例。
在下文中一共展示了StyleConstants.setFontSize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例7: 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);
}
示例8: 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;
}
示例9: 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);
}
示例10: init
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/**
* Description of the Method
*
* @param prop
* Description of the Parameter
*/
public void init(YassProperties prop) {
String fontSizeString = prop.getProperty("lyrics-font-size");
try {
int i = Integer.parseInt(fontSizeString);
if (i > 0) {
fontSize = i;
}
} catch (Exception e) {
}
StyleConstants.setFontSize(notLongStyle, fontSize);
}
示例11: 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;
}
示例12: 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);
}