java的字體大小設置
㈠ 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-Eclipse編輯框和控制台的字體大小
打開Eclipse,選擇windows(系統)選項
然後點開--->preferences(首選項)
彈出首選項的窗口點擊Appearance(外觀)
再點擊color and font (顏色和字體)
再點擊Java---->Java editor text font(java 編輯器文本字體)
再點擊Edit進行編輯
設置字體大小
控制台的字體設置點擊Debug----->點擊console font(控制台字體)步驟同上面一樣點擊Edit,進行字體大小設置
㈢ java怎麼縮小字體
摘要 打開eclipse找到工具欄的Window 選擇Preferences。
㈣ java中如何設置按鈕文字的大小、顏色和字體
submit= new JButton("登陸");
submit.setFont(new Font("宋體", Font.PLAIN, 16));
三個參數分別表示: 字體,樣式(粗體,斜體等),字型大小
submit.setForeground(Color.RED);
這個表示給組件上的文字設置顏色Color.RED表示紅色
當然你也可以自己給RGB的值 比如 submit.setForeground(new Color(215,215,200));
JLabel組件支持HTML標記代碼
infoLab= new JLabel("<html><a href='地址'>用戶登陸系統</a></html>", JLabel.CENTER);
*注意:地址要單引號引起來。這個表示給用戶登錄系統幾個字增加超鏈接
infoLab .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
這個表示給這個文字添加滑鼠樣式,當滑鼠移動到文字上,滑鼠變成手型
㈤ Java中怎麼設置JLabel的字體樣式,大小,顏色
1、打開Myeclipse的相關界面,在Window那裡點擊Preferences。
㈥ 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));
㈦ java裡面怎麼設置字體大小
JTextArea t = new JTextArea();
Font font = new Font("Default",Font.PLAIN,size);
t.setFont(font);
//其中size 就是字體的大小,可以設置。只要再用t.setFont()安裝新的字體就行了。
㈧ 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的編程環境里怎麼去設置中文的字體大小
在
MyEclipse
的工具欄中選擇
Window
的
Preferences
選項:
在彈出框中選擇第一個
General
下的->
Appearance
下的->
Colors
and
Fonts
->
在左邊選擇
Java
下的->
Java
Editor
Text
Font
,選中後右邊有一個
Change
,點擊它會彈出一個字體對話框
裡面可設置編程時,代碼的字體、字形、大小等,選擇後確定即可!