String msg = "asergre4545dgfdfg45";
String dateMonthMsg = "明细";
JOptionPane.showMessageDialog(null, msg, dateMonthMsg, JOptionPane.INFORMATION_MESSAGE);
 我想让弹出的消息对话框里,数字是红色的。字母和汉字是兰色的
能做到么? 

解决方案 »

  1.   


    // String msg = "asergre4545dgfdfg45";

    String str1 = "<font color=\"blue\">asergre</font>", 
           str2 = "<font color=\"red\">4545</font>", 
           str3 = "<font color=\"blue\">dgfdfg可以吗?</font>", str4 = "<font color=\"red\">45</font>"; String msg = "<html>" + str1 + str2 + str3 + str4 + "</html>"; String dateMonthMsg = "明细";
    JOptionPane.showMessageDialog(null, msg, dateMonthMsg,
    JOptionPane.INFORMATION_MESSAGE);
    上面这种方法可是可以,但是有点....你可以写个方法去实现判断字符串的.
    是数字就:"<font color=\"red\">4545</font>", 
    是字母就:"<font color=\"blue\">asergre</font>", 
    是汉字就:"<font color=\"blue\">asergre</font>"
    然后连接连接字符串.return;
      

  2.   

    楼上的方法非常好
    SWING里面的组件都是支持以HTML方式呈现的
      

  3.   

    的确,最简便的方法只有用HTML了
      

  4.   

    String table= "阿布ab";
    String dateMonthMsg = "明细";
    JOptionPane.showMessageDialog(this, table, dateMonthMsg, JOptionPane.INFORMATION_MESSAGE);
    想要特别的要求,那就用substring()方法,取得其中的需要的字符啊,然后经过获得的值经过颜色转变传到消息对话框中啊!!
      

  5.   

    我要是早点看到这个帖子就不用郁闷很久了,我也是遇到同样的问题,最后是有人指点我才知道原来swing支持HTML!
    学习了!
      

  6.   

    呃,原来SWING支持HTML啊,真是长见识了