java - How to disable the ability to click on the JTextArea
问题描述
I need to disable the ability to click your mouse in the JTextArea.
Below is what I currently have for my JTextArea:
textArea1 = new JTextArea();
textArea1.setBorder(BorderFactory.createLineBorder(Color.black, 1));
DefaultCaret caret = (DefaultCaret) textArea1.getCaret(); // this line and the line below was inspired by a comment found here: https://stackoverflow.com/questions/15623287/how-to-always-scroll-to-bottom-of-text-area
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
textArea1.setEditable(false);
JScrollPane scrollPane1 = new JScrollPane(textArea1)
Once you press on the JTextArea with your mouse, it almost stops the whole DefaultCaret method from working. I thought previously it was because you could highlight but that was not the case.
The DefaultCaret method causes the JTextArea to always be at the bottom when new text gets added to the textarea.
解决方案
推荐阅读
- javascript - 对象分配在执行分配之前操作对象。如何?
- wordpress - 媒体库未在 wordpress 2018 上显示图像
- ssis - 将 SSIS 包从我的本地系统执行到其他远程服务器,SSIS 包存储在文件系统中
- java - java.nio.channels.Selector.select() 立即返回 0
- wpf - 如何更新绑定到 UI 的集合?
- javascript - Django-如何通过 javascript 变量在模板中定义 django 变量?
- fpga - 使用 PCI EXPRESS 进行 FPGA 到 PC 的数据传输
- php - 将 Unicode 转换为 PHP 数组中的 HTML 实体
- cordova - Cordova 坚持将其添加到项目中
- java - Angular ng-cloak 与 Thymeleaf