如何把JTextArea里的内容清空或用其他字符串赋值,怎么设成不可编辑

本文介绍如何使用Java Swing组件JTextArea进行内容清空、赋值及设置不可编辑状态的方法。通过简单示例展示如何利用setText方法清空文本区内容或设置为特定字符串,以及如何通过setEditable方法控制文本区的编辑权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何把JTextArea里的内容清空或用其他字符串赋值?还有怎么设成不可编辑?

 

1.如何把JTextArea里的内容清空或用其他字符串赋值?还有怎么设成不可编辑?


该类里没有这些方法,只有一个replaceRange(String str, int start, int end),但那个end好象很难知道用什么值。我要全部替换。

2.Re:如何把JTextArea里的内容清空或用其他字符串赋值?还有怎么设成不可编辑?


JTextArea TA1 = new JTextArea();
1)清空:
TA1.setText("");
2)其它串如:Str1
TA1.setText(Str1);
3)不可编辑:
TA1.setEditable(false);

3.Re:如何把JTextArea里的内容清空或用其他字符串赋值?还有怎么设成不可编辑?


JTextArea is the sub-class of JTextComponent so you can use all the method defined in the JTextComponent, such as setText(null), setEditable(boolean), etc.

4.Re:如何把JTextArea里的内容清空或用其他字符串赋值?还有怎么设成不可编辑?

shsen,java api doc is very helpful. Recommend you to download and take it as reference while coding. You can find all of the api you want .

5.Re:如何把JTextArea里的内容清空或用其他字符串赋值?还有怎么设成不可编辑? ]

looker wrote:
shsen,java api doc is very helpful. Recommend you to download and take it as reference while coding. You can find all of the api you want .


nod, 不过我经常用的是chm格式的api doc, 好处是直接在索引栏中输入setSize,就会调转到相应的apidoc, 效率比较高
另外一个就是JBuilder加上ProductityPro插件, 显示光标的api doc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值