请问:java应用程序(非web的)中,如何设置字体的显示颜色?如:我在一个文本框中输入一个aaa,然后用一个对话框显示出来:what you are inputing is aaa,其中aaa要为红色,其他的字体不变,如何实现?谢谢!

解决方案 »

  1.   

    http://topic.csdn.net/t/20030416/16/1669522.html
      

  2.   


    用 setForeground方法 public class Testsetcolor {
    public static void main(String[] args) {
    Frame f = new Frame("testSetColor");
    f.setBounds(300, 300, 400, 300);

    Label l1 =  new Label("TestColor");

    l1.setForeground(Color.RED);  //字体颜色设置为红色
    f.add(l1);
    f.setVisible(true);
    } }
      

  3.   

    谢谢,可能你们还没有理解我的意思。我的需求是:现在有一个文本框和一个按钮,我在文本框中填入aaa,点击按钮后,会弹出一个提示对话框(JOptionPane.showMessageDialog(null,文本框输入的类容(aaa)+"is not allowed to input!"))显示:aaa is not allowed to input!.其中文本框中的颜色默认时黑色,而要求这个提示对话框中的aaa需要显示为红色,其他的字还是黑色,明白了吗?请高手解答。谢谢!