復(fù)制以下代碼,修改相應(yīng)地方即可:
為塔河等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及塔河網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站建設(shè)、網(wǎng)站制作、塔河網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
private?static?void?loadIndyFont()
{
UIManager.put("CheckBox.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Tree.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Viewport.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("ProgressBar.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("RadioButtonMenuItem.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("FormattedTextField.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("ToolBar.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("ColorChooser.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("ToggleButton.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Panel.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("TextArea.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Menu.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("RadioButtonMenuItem.acceleratorFont",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Spinner.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Menu.acceleratorFont",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("CheckBoxMenuItem.acceleratorFont",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("TableHeader.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("TextField.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("OptionPane.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("MenuBar.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Button.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Label.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("PasswordField.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("InternalFrame.titleFont",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("OptionPane.buttonFont",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("ScrollPane.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("MenuItem.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("ToolTip.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("List.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("OptionPane.messageFont",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("EditorPane.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("Table.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("TabbedPane.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("RadioButton.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("CheckBoxMenuItem.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("TextPane.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("PopupMenu.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("TitledBorder.font",?new?java.awt.Font("宋體",?0,?12));
UIManager.put("ComboBox.font",?new?java.awt.Font("宋體",?0,?12));
}
java中沒有自帶的字體對話框,這需要自己來編寫。
text.setFond("字體名字",字形(如,fond.bold),大小)
import java.awt.*;
import java.awt.event.*;
import javax.swing.JColorChooser;
//import javax.swing.border.*;
class ff extends Frame implements ActionListener
{
Choice font,size,bolder;
Button bb;
ff(String s)
{
setTitle(s);
font=new Choice();
bolder=new Choice();
size=new Choice();
//bolder.add加監(jiān)視器
//font.add加監(jiān)視器
//size.add加監(jiān)視器
Panel p1=new Panel();
Panel p2=new Panel();
bb=new Button("點擊打開");
bb.addActionListener(this);
p1.setLayout(new GridLayout(4,1));
p2.setLayout(new GridLayout(4,1));
GraphicsEnvironment gg=GraphicsEnvironment.getLocalGraphicsEnvironment();
String ss[]=gg.getAvailableFontFamilyNames();
String bold[]={"Font.BOLD","Font.CENTER_BASELINE","Font.CENTER_BASELINE","Font.ITALIC",
"Font.PLAIN","Font.ROMAN_BASELINE","Font.TRUETYPE_FONT"};
for(int i=126;iss.length;i++)
font.add(ss[i]);
for(int i=12;i=64;i+=2)
{
String w=String.valueOf(i);
size.add(w);
}
for(int i=0;ibold.length;i++)
{
bolder.add(bold[i]);
}
p1.add(new Label("請選擇字體"));
p1.add(font);
p1.add(new Label("請選擇大小"));
p1.add(size);
p2.add(new Label("請選擇字型"));
p2.add(bolder);
p2.add(new Label("請選擇字體顏色"));
p2.add(bb);
add(p2,BorderLayout.WEST);
add(p1,BorderLayout.EAST);
setSize(250,150);
setVisible(true);
pack();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent ee)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
Color cc=JColorChooser.showDialog(this,"顏色對話框",null);
bb.setBackground(cc);//應(yīng)用舉例
}
}
public class font
{
public static void main(String[] args)
{
new ff("字體對話框");
}
}
Java設(shè)置label字體代碼如下:
ublic?class?SetColor?extends?JFrame{
JLabel?jlabel?=?new?JLabel("顏色,大小");
public?SetColor(){
this.setLayout(null);
jlabel.setBounds(0,?0,?200,?40);
jlabel.setFont(new?Font("",1,30));//設(shè)置字體大小
jlabel.setForeground(Color.BLUE);//設(shè)置字體顏色
this.add(jlabel);
this.setSize(200,200);
this.setVisible(true);
}
/**
*?@param?args
*/
public?static?void?main(String[]?args)?{
//?TODO?Auto-generated?method?stub
SetColor?sc?=?new?SetColor();
}}
Java Swing中可以給每個控件設(shè)置字體格式和其他屬性的設(shè)置,示例如下:\x0d\x0asubmit= new JButton("登陸");\x0d\x0asubmit.setFont(new Font("宋體", Font.PLAIN, 16));\x0d\x0a三個參數(shù)分別表示: 字體,樣式(粗體,斜體等),字號\x0d\x0a submit.setForeground(Color.RED);\x0d\x0a這個表示給組件上的文字設(shè)置顏色Color.RED表示紅色\x0d\x0a當(dāng)然你也可以自己給RGB的值 比如 submit.setForeground(new Color(215,215,200));