请问jFrame中的jtextare怎么设置文字的大小、颜色、字体。不是按一个选择就把所有的改掉那种,是改变你选择的文字的属性,并且下面输入的文字属性也保持在你选择的那种

解决方案 »

  1.   

    JTextArea 做不到你的要求。
    需要使用 JTextPane
      

  2.   

    JTextArea使用的是PlainDocument, 此document不能进行多种格式的着色.
    JTextPane, JEditorPane使用的是StyledDocument, 默认就可以使用. 
      

  3.   

    JButton colorBtn;
    JTextArea txtArea;
    JButton colorBtn;
    public void actionPerformed(ActionEvent e){ 
       if(e.getSource()==colorBtn){//改变颜色 
         colorStyle=JColorChooser.showDialog(this,"选择字体颜色",colorStyle); 
         colorBtn.setForeground(colorStyle); 
         txtArea.setForeground(colorStyle); 
       } 
       else if(e.getSource()==inputText){//将输入文字在文字显示区表示; 
         txtArea.setText(inputText.getText()); 
       } 
    能改变颜色,但是我不知道怎么改变字体大小什么的