字體java
A. java 設置字體格式
Java Swing中可以給每個控制項設置字體格式和其他屬性的設置,示例如下:
submit= new JButton("登陸");
submit.setFont(new Font("宋體", Font.PLAIN, 16));
三個參數分別表示: 字體,樣式(粗體,斜體等),字型大小
submit.setForeground(Color.RED);
這個表示給組件上的文字設置顏色Color.RED表示紅色
當然你也可以自己給RGB的值 比如 submit.setForeground(new Color(215,215,200));
B. java字體庫中的字體列印不出來
java字體庫中的字體列印不出來的原因如下:
javac Hallojava.java是編譯這個文件,要列印出來你還需要打java Hallojava去運行它的class文件。
Java是一門面向對象的編程語言,不僅吸收了C++語言的各種優點,還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特徵。Java語言作為靜態面向對象編程語言的代表,極好地實現了面向對象理論,允許程序員以優雅的思維方式進行復雜的編程。
C. java 字體設置
1、對字體的操作
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setFontFamily(attr, family);
setCharacterAttributes(editor, attr, false);
family為字體
2、對字體大小的操作
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setFontSize(attr, size);
setCharacterAttributes(editor, attr, false);
size為字型大小
3、是否是粗體的操作
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean bold = (StyleConstants.isBold(attr)) ? false : true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setBold(sas, bold);
setCharacterAttributes(editor, sas, false);
4、是否是斜體的操作
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean italic = (StyleConstants.isItalic(attr)) ? false : true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setItalic(sas, italic);
setCharacterAttributes(editor, sas, false);
5、是否有下劃線的操作
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean underline = (StyleConstants.isUnderline(attr)) ? false
: true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setUnderline(sas, underline);
setCharacterAttributes(editor, sas, false);
6、左中右對齊的處理
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setAlignment(attr, a);
setParagraphAttributes(editor, attr, false);
public static final void setParagraphAttributes(JEditorPane editor,
AttributeSet attr, boolean replace) {
int p0 = editor.getSelectionStart();
int p1 = editor.getSelectionEnd();
StyledDocument doc = getStyledDocument(editor);
doc.setParagraphAttributes(p0, p1 - p0, attr, replace);
}
a:0:左,1:中,2:右
7、文本字體顏色的設置
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setForeground(attr, fg);
setCharacterAttributes(editor, attr, false);
fg:為color
8、文本背景顏色的設置
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setBackground(attr, bg);
setCharacterAttributes(editor, attr, false);
D. java字體設置
字體 Font
setFont("隸書",Font.ITATIC,23)
意思就是("字體名字",字形(如,fond.bold),大小)
等等
E. 你們在編寫java的代碼的時候一般用什麼樣的字體
一般適合用作程序代碼顯示的字體,有下列幾個:
(1):Courier New 9pt, Verdana, Lucida Console (宋體,新宋體等不在討論之列)
首先說說Courier New, 這個字體雖說經典,但總體感覺其實不好。因為是等寬字體,所以對編程而言,其優點是每個字元區分的十分清楚,方便查找程序中的輸入錯誤。不好的地方在於,因為是等寬字體,特別浪費顯示空間,在看代碼的時候恨不得顯示器變成 21寸的才好。總之就是感覺用來看那種大的框架的源代碼的時候,非常不適合。一屏只能看到很少的幾句代碼,有隻見樹木,不見森林之感,不利於從宏觀角度理解代碼的邏輯。另外在 VS.NET 2003 裡面該字體顯示的中文特別大,而且很醜陋 -_-!
(2):Verdana: 非等寬字體。總體可讀性好些,但是小的錯誤,比如多一個少一個空格之類的,很難排查。
Lucida Console 是等寬字體。可讀性也不錯,但是 vs.Net 顯示出來有鋸齒。
serif 字體通常不同筆順的粗細有別,且起筆落筆處有多餘的小折線。
sans-serif 字體筆畫不論方向粗細相同,且起筆落筆沒有多餘折線。
中文字體中,可以與此類比:宋體相當於 serif 字體,黑體相當於 sans-serif 字體。
正文中應該用 serif 字體以提高可讀性,標題可以用 sans serif 字體以示強調。
(3):serif 字體在視覺上強調單詞的整體,因此作為正文更可讀;而 sans serif 強調單個的字母。
研究顯示,在 web 中 sans-serif 字體更易閱讀。正文字體比較好的選擇:Arial 9.75 或 MS Sans Serif 9.75。為了提高閱讀准確性和速度,最好的字體大小是 8.25, 9.0, 或 9.75("MS Serif 8.25" 除外)。
(4)養眼的編輯器配色
環境:VS2005
字體:Verdana, 10pt
普通文本背景色:238,239,230 (#E6EFEE)