日期:2014-05-20  浏览次数:20856 次

如何在textarea中实现选中文本的字体转换?
小菜初学java,想写个记事本,我想问下怎样设置选中字体的颜色呢?

------解决方案--------------------
我想在TextArea中好像没有方法设置你选定文本的颜色吧,不过有一个方法setForeground(Color c)可以设置所有文本的颜色.
------解决方案--------------------
自己查API吧
------解决方案--------------------
JTextArea.setSelectedTextColor(Color c);

TextArea中没有。
------解决方案--------------------
是不是还有JTextPane,是不是这个更好用一些。
------解决方案--------------------
这个你看看,在线编辑器字体变色。
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<script language= "javascript ">
function getIframeData(){
document.form1.test.value=HtmlEdit.document.body.innerHTML;
}
function sentIframeData(){
HtmlEdit.document.body.innerHTML=document.form1.test.value;
}
function doColor(){
HtmlEdit.focus();
var sel = HtmlEdit.document.selection.createRange();
insertHTML( " <font color=red> "+sel.text+ " </font> ");
}
function document.onreadystatechange()
{
HtmlEdit.document.designMode= "On ";
}
function insertHTML(html) {
HtmlEdit.document.selection.createRange().pasteHTML(html);
}
</script>
</head>
<body>
<form action= "test.asp?act=add " method= "post " name= "form1 ">
<IFRAME id=HtmlEdit style= "WIDTH: 100%; HEIGHT: 296px " marginWidth=0 marginHeight=0>
</IFRAME>
<textarea name= "test " rows= "10 " id= "test " style= "width:100%; "> </textarea>
<br>
<input type= "submit " name= "Submit " value= "submit ">
<input type= "button " value= "iframe-> textarea " onClick= "getIframeData() ">
<input type= "button " value= "textarea-> iframe " onClick= "sentIframeData() ">
<input type= "button " value= "color " onClick= "doColor() ">
</form>
</body>
</html>
------解决方案--------------------
wo yong guo le ,hai shi bu xing ?