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();
bb.addActionListener(this);
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"};
font.add(ss[i]);
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);
add(p1,BorderLayout.EAST);
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("字体对话框");
setTextColor(0xFF0000FF);
setTextColor(Color.parseColor("#FFFFFF"));
//还有就是使用资源文件进行设置
setTextColor(this.getResources().getColor(R.color.blue));
//通过获得资源文件进行设置.根据不同的情况R.color.blue也可以是R.string.blue或者
//另外还可以使用系统自带的颜色类
setTextColor(android.graphics.Color.BLUE);
Java Swing中可以给每个控件设置字体格式和其他属性的设置,示例如下:
submit= new JButton("登陆");
三个参数分别表示: 字体,样式(粗体,斜体等),字号
submit.setForeground(Color.RED);
这个表示给组件上的文字设置颜色Color.RED表示红色
TextView mName = (TextView)findViewById(R.id.name);
//给一个id为name的TextView设置字体大小
mName.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimensionPixelSize(R.dimen.my_text_size));
getDimensionPixelSize()方法返回的是像素数值,所以mName.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimensionPixelSize(R.dimen.my_text_size)); 是这样的写法.
以上就是土嘎嘎小编为大家整理的JAVA动画字体设置代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!