[英]Java: How to I change the color of a specific line or row of string in a Text area?
我可以改變顏色的一種方法是使用setForground()。 但是,當有多行代碼時,它會使所有內容變為綠色或黑色。 有沒有其他方法或任何方法來解決這個問題? 謝謝!
int key = evt.getKeyCode();
if (key == KeyEvent.VK_ENTER)
{
String tb1EnterdValue = tb1.getText().toString();
if((tb1EnterdValue.equals("yes")) )
{
TextArea1.setForeground(Color.green);
else
{
TextArea1.setForeground(Color.lightGray);
}
this.TextArea1.append(">"+tb1EnterdValue+newline);
this.tb1.setText("");
這是Swing,你在使用JTextAreas嗎? 如果是這樣,請在您的問題中具體說明,然后不要使用JTextArea,因為如果您希望在一個文本組件中包含多種格式,則它不是理想的文本組件。 而是考慮使用JTextPane或JEditorPane。 教程將向您展示如何使用它們以及何時使用它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.