复制以下代码,修改相应地方即可:
为塔河等地区用户提供了全套网页设计制作服务,及塔河网站建设行业解决方案。主营业务为网站建设、网站制作、塔河网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
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加监视器
//font.add加监视器
//size.add加监视器
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);//应用举例
}
}
public class font
{
public static void main(String[] args)
{
new ff("字体对话框");
}
}
Java设置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));//设置字体大小
jlabel.setForeground(Color.BLUE);//设置字体颜色
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中可以给每个控件设置字体格式和其他属性的设置,示例如下:\x0d\x0asubmit= new JButton("登陆");\x0d\x0asubmit.setFont(new Font("宋体", Font.PLAIN, 16));\x0d\x0a三个参数分别表示: 字体,样式(粗体,斜体等),字号\x0d\x0a submit.setForeground(Color.RED);\x0d\x0a这个表示给组件上的文字设置颜色Color.RED表示红色\x0d\x0a当然你也可以自己给RGB的值 比如 submit.setForeground(new Color(215,215,200));