java改变字体的代码 java如何修改字体
java 如何设置字体格式?
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));
成都创新互联公司坚信:善待客户,将会成为终身客户。我们能坚持多年,是因为我们一直可值得信赖。我们从不忽悠初访客户,我们用心做好本职工作,不忘初心,方得始终。十年网站建设经验成都创新互联公司是成都老牌网站营销服务商,为您提供成都网站建设、网站建设、网站设计、html5、网站制作、高端网站设计、小程序开发服务,给众多知名企业提供过好品质的建站服务。
Java中设置字体
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的字体大小及颜色显示
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中如何更换窗口标题栏字体(如何通过软件代码修改)
复制以下代码,修改相应地方即可:
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改变字体的代码 java如何修改字体
文章分享:http://ybzwz.com/article/doiedco.html