在JTEXTAREA中怎么改变选中文本的字体,颜色和一些外部特性能

解决方案 »

  1.   

    JTextPane textPane = new JTextPane();
        StyledDocument doc = textPane.getStyledDocument();
        
        // Makes text red
        Style style = textPane.addStyle("Red", null);
        StyleConstants.setForeground(style, Color.red);
        
        // Inherits from "Red"; makes text red and underlined
        style = textPane.addStyle("Red Underline", style);
        StyleConstants.setUnderline(style, true);
        
        // Makes text 24pts
        style = textPane.addStyle("24pts", null);
        StyleConstants.setFontSize(style, 24);
        
        // Makes text 12pts
        style = textPane.addStyle("12pts", null);
        StyleConstants.setFontSize(style, 12);
        
        // Makes text italicized
        style = textPane.addStyle("Italic", null);
        StyleConstants.setItalic(style, true);
        
        // A style can have multiple attributes; this one makes text bold and italic
        style = textPane.addStyle("Bold Italic", null);
        StyleConstants.setBold(style, true);
        StyleConstants.setItalic(style, true);
        
        // Set text in the range [5, 7) red
        doc.setCharacterAttributes(5, 2, textPane.getStyle("Red"), true);
        
        // Italicize the entire paragraph containing the position 12
        doc.setParagraphAttributes(12, 1, textPane.getStyle("Italic"), true);
      

  2.   

    http://www.javaref.cn/egs/javax.swing.text/style_HiliteWords2.html
      

  3.   

    转错了,抱歉,这个
    http://www.blogjava.net/Sprite-bei/archive/2007/01/25/95996.aspx
      

  4.   

    呜呜,又错了,看这篇,上面两个作为参考
    http://huij.net/html/JAVAjishu/GUI_sheji/19990720/13906.html
      

  5.   

    非常感谢,原来是JTEXTAREA只能整体的变呀,我还想了好多办法结果都不行呢,呵呵
      

  6.   

    对了,要想用JAVA搜索到所有当前局域网的计算机,并可以控制它们,比如说结束他们的进程呀和截屏什么的,请问有什么类实现了这些功能呢,如果没有怎么使JAVA和底层交互或者编一个那样的类.
      

  7.   

    如果想看截屏并远程控制的话,可以试试这个类java.awt.Robot,他可以看到远程的屏幕,并可以根据鼠标的动作来编写相应的方法。
      

  8.   

    不用客气,直接看JAVA API 就可以