日期:2014-05-20 浏览次数:20728 次
import java.awt.Color; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.text.Caret; import javax.swing.text.DefaultCaret; public class MyCaretTest extends JFrame { private JTextArea messageArea; private Caret myCaret; public MyCaretTest() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(100, 100, 500, 500); createMessageArea(); this.getContentPane().add(messageArea); this.setVisible(true); } public JTextArea createMessageArea() { messageArea = new JTextArea(); myCaret=new DefaultCaret(); myCaret.setBlinkRate(500);//设置闪烁率 messageArea.setCaret(myCaret); messageArea.setCaretColor(Color.RED);//设置颜色 return messageArea; } public static void main(String[] args) { new MyCaretTest(); } }