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