Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display red text in a JTextArea?

Tags:

java

swing

I want to show error(text) in result in red color after compiling exec file and display it in textarea of gui using swing in java.

like image 788
smita Avatar asked Jan 29 '26 17:01

smita


2 Answers

A normal JTextArea doesn't support fancy things like different colors of text. However, there are similar components that do. See http://java.sun.com/docs/books/tutorial/uiswing/components/text.html

like image 153
Tyler Avatar answered Feb 01 '26 09:02

Tyler


JEditorPane can get content formatted in HTML. The official Sun tutorial also gives some insight:

The JTextArea class provides a component that displays multiple lines of text and optionally allows the user to edit the text. If you need to obtain only one line of input from the user, you should use a text field. If you want the text area to display its text using multiple fonts or other styles, you should use an editor pane or text pane. If the displayed text has a limited length and is never edited by the user, use a label.

like image 25
Xr. Avatar answered Feb 01 '26 07:02

Xr.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!