改变JTextArea显示的颜色,不是全部变色啊?像 JTextArea.append("<html><font>uiouo</font></html>");
就别说了啊 ,那是不行的。各位大哥帮帮忙,急用 ,最好有个可执行的例子,谢谢

解决方案 »

  1.   

    是这样的效果么?public class TestJ extends JFrame
    {    public TestJ()
        {
            this.setLayout(null);
            JTextArea jt = new JTextArea();
            jt.setBackground(new Color(100, 125, 3));
            this.add(jt);
            jt.setBounds(10, 10, 120, 80);
            // 窗体居中
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = this.getSize();        if (frameSize.height > screenSize.height)
            {
                frameSize.height = screenSize.height;
            }
            if (frameSize.width > screenSize.width)
            {
                frameSize.width = screenSize.width;
            }        this.setLocation((screenSize.width - frameSize.width) / 2 - 280,
                    (screenSize.height - frameSize.height) / 2 - 350);        // 设置
            this.setResizable(false);
            this.setTitle("");
            this.setSize(560, 670);
            this.setVisible(true);
        }    /**
         * @param args
         */
        public static void main(String[] args)
        {
            new TestJ();
        }}
      

  2.   

    不行吧!
    JTextArea是一个整体,里面的内容只能是一样的字体和颜色
      

  3.   

    amdgaming  谢谢,你那是背景色吧   我要的是单行字体颜色
      

  4.   

    把JTextArea设置透明!!
    然后设置JFrame背景的颜色  就可以了!!
    甚至可以设置背景图片
      

  5.   

    setForeground(Color.RED);会改变所有JTextArea中的颜色   
      怎么选择输出   
      普通信息为蓝色   
      警告信息为红色   
      请各位执教 
      

  6.   

    你可以设置个图片啊 
    图片用ps很容易的吧
    再加进去就ok了
      

  7.   

    用JTextPanel好了:
    package com.gui;import java.awt.Color;
    import java.lang.reflect.InvocationTargetException;import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.SwingUtilities;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.DefaultStyledDocument;
    import javax.swing.text.Style;
    import javax.swing.text.StyleConstants;
    import javax.swing.text.StyleContext;public class JTextPanelTest extends JFrame {
    private JTextPane textPanel; private StyleContext styleContext; private DefaultStyledDocument doc; public JTextPanelTest() {
    initCompoment();
    } public void initCompoment() {
    styleContext = new StyleContext();
    doc = new DefaultStyledDocument(styleContext);
    textPanel = new JTextPane(doc); // 设置绿色文本
    final Style greenStyle = styleContext.addStyle("ConstantWidth", null);
    StyleConstants.setFontFamily(greenStyle, "monospaced");
    StyleConstants.setForeground(greenStyle, Color.green); // 设置黄色文本
    final Style yellowStyle = styleContext.addStyle("ConstantWidth", null);
    StyleConstants.setFontFamily(yellowStyle, "monospaced");
    StyleConstants.setForeground(yellowStyle, Color.yellow); // 设置蓝色文本
    final Style blueStyle = styleContext.addStyle("ConstantWidth", null);
    StyleConstants.setFontFamily(blueStyle, "monospaced");
    StyleConstants.setForeground(blueStyle, Color.blue);

    try {
    SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
    try {
    // 将文本添加到文档中
    doc.insertString(0, text, null);
    // 设置第一段为绿色
    doc.setParagraphAttributes(0, 1, greenStyle, false);
    // 设置第二段为黄色
    doc.setParagraphAttributes(12, 1, yellowStyle, false);
    // 设置第三四段为蓝色
    doc.setParagraphAttributes(25, 13, blueStyle, false); } catch (BadLocationException e) {
    }
    }
    });
    } catch (InterruptedException e) {
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    e.printStackTrace();
    }
    this.add(new JScrollPane(textPanel));
    } public static final String text = "Hello World\n" + "Hello World\n"
    + "Hello World\n" + "Hello World\n" + "Hello World\n"; public static void main(String[] args) {
    JTextPanelTest frame = new JTextPanelTest();
    frame.setSize(400, 300);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }
      

  8.   

    #4楼
    把JTextArea设置透明!! 
    然后设置JFrame背景的颜色  就可以了!! 
    甚至可以设置背景图片真的很有创意,谢谢你
      

  9.   

    setForeGround(Color.Red)
    这个是改变文字的颜色
    背景色是backGround