日期:2014-05-20  浏览次数:20714 次

如何设置字体颜色 大小在下面程序中 急忘解决
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号字