❶ java中控制字體大小的設置
改成這樣就可以了
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class controlString extends Applet implements ActionListener {
Button btn1, btn2;
int i = 20;
TextArea tx;
public void init() {
btn1 = new Button("big");
btn2 = new Button("small");
tx = new TextArea(50, 50);
add(btn1);
add(btn2);
add(tx);
tx.setFont(new Font("SansSerif", Font.BOLD, i));
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1 && i < 60) {
i = i + 4;
tx.setFont(new Font("SansSerif", Font.BOLD, i));
tx.setText("i is changed to" + i);
} else if (e.getSource() == btn2 && i > 4) {
i = i - 4;
tx.setFont(new Font("SansSerif", Font.BOLD, i));
tx.setText("i is changed to" + i);
}
}
}
------------------
Font font1=new Font("SansSerif",Font.BOLD,i);
在這里 你創建了一個對象font1,然後其屬性都在這里定義了;之後你增加了變數i,但是這並不影響對象中的屬性,對象的屬性還是和之前定義時一樣;所以不會改變。。。
❷ java的編程環境里怎麼去設置中文的字體大小
在
MyEclipse
的工具欄中選擇
Window
的
Preferences
選項:
在彈出框中選擇第一個
General
下的->
Appearance
下的->
Colors
and
Fonts
->
在左邊選擇
Java
下的->
Java
Editor
Text
Font
,選中後右邊有一個
Change
,點擊它會彈出一個字體對話框
裡面可設置編程時,代碼的字體、字形、大小等,選擇後確定即可!
❸ 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);
❹ java如何設置文字的格式,例如大小,顏色,字體··等等!
reset.setFont(new Font("",1,18));
你這里的""不能這樣寫,里邊是字體名稱,要麼宋體或其它字體的名稱或者寫null,這些字體必須是你電腦上有的
❺ 如何把java工作區的字體調大
看你的是什麼編譯器,
要是jcreator的話,在菜單欄中點擊configue,選擇opinion進入java/font即可更改字體大小也就是中文版的配置/選象/java/字體
要是Eclipse的話,在菜單欄中點擊串口,選擇首選項,點常規,點外觀,點顏色和字體,點Java,點Java編譯器文本字體
要實MyEclipse的話,Window --> Preferences --> General --> Appearance --> Colors and Fonts --> Basic --> Text Font --> Change
要是你的是別的編譯器,把名字發上來,我幫你解答
❻ Java中怎麼設置JLabel的字體樣式,大小,顏色
1、打開Myeclipse的相關界面,在Window那裡點擊Preferences。
❼ 怎麼調整Java-Eclipse編輯框和控制台的字體大小
打開Eclipse,選擇windows(系統)選項
然後點開--->preferences(首選項)
彈出首選項的窗口點擊Appearance(外觀)
再點擊color and font (顏色和字體)
再點擊Java---->Java editor text font(java 編輯器文本字體)
再點擊Edit進行編輯
設置字體大小
控制台的字體設置點擊Debug----->點擊console font(控制台字體)步驟同上面一樣點擊Edit,進行字體大小設置
點擊Apply>ok,不要粗心大意點錯了!祝你好運!
❽ java裡面怎麼設置字體大小
JTextArea t = new JTextArea();
Font font = new Font("Default",Font.PLAIN,size);
t.setFont(font);
//其中size 就是字體的大小,可以設置。只要再用t.setFont()安裝新的字體就行了。
❾ 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));