读书人

怎么设置字体颜色 大小在下面程序中 急

发布时间: 2012-02-05 12:07:14 作者: rapoo

如何设置字体颜色 大小在下面程序中 急忘解决
import javax.swing.*;

public class TextMove
{
JLabel lab;
int i;
String str;

public TextMove()
{
JFrame frame = new JFrame("TextMove");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,200);
// Font f=new Font("")
str = "I'm moving...";
lab = new JLabel(str);
frame.add(lab);
frame.setVisible(true);
i=0;
while(true)
{

str = " "+str;
try
{
Thread.sleep(200);
lab.setText(str);
}
catch(InterruptedException e)
{
}
}
}

public static void main(String args[])
{
new TextMove();
}
}


[解决办法]
你是要对lab设置字体吗,
我是这样写的:
label.setFont(new Font("宋体", Font.ITALIC, 8));

这个label的字体是宋体,斜体,8号字

读书人网 >J2SE开发

热点推荐