I want to make selected text of jtextarea underline while clicking a spicified button. this task I have accomplish in jtextpane but I need it in jtextarea any suggestions please.
Use a JTextPane (or JEditorPane), where you can use HTML tags to accomplish that.
The text of a JTextArea cannot be formatted in parts, as indicated here, for example:
A JTextArea is a multi-line area that displays plain text.
I want to make selected text of jtextarea underline
You can add a Highlighter to the text area and use a custom Painter to highlight the text. The default painter paints the entire background of the highlighted text, but you can customize the Painter to do whatever you want.
Check out Rectangle Painter for a couple examples of creating your own custom Painter.
Related
I am developing a spam detector application using Java GUI (NetBeans). Now I have a simple user interface which includes a text area in which the user is going to paste his email in to order to check if its a spam or not, but the problem is when you paste a text in the text area all the text properties will be lost such as : Font type, color, hyperlinks etc...
So what should I do?
That's because you need RTF-enabled Swing component to visualize various text properties.
JTextArea is visualizing only plain text. Use JEditorPane or JTextPane instead.
I'm currently developing JTextArea with a Notepad++ like function (currently indentation function finished).
Now I'm trying to add a function which in my JTextArea will show a dotted line for an indentation with same level, and change specific color of a word.
Thanks in advance :)
You will not able to achieve your target with JTextArea as it is a plain text support component.You have to use a Styled text supported JEditorPane or JTextPane.And try to use a HTML document and achieve it.Look at
Styled supported components
and
some more examples
In JFrame Form I have added a jTextArea and added a text into it, while still in design mode. But when I run the form I want the text to be invisible, which is not happening. I checked the properties of the JTextArea but I am not really sure how to change the visiblity of the text..
For clearing the JTextArea filed you need to set its text as empty.
For this you need to see JTextArea#setText as null or "".Try this code at the execution of your application.
jTerxtAreaObject.setText("");
Set the color of the text as the same color as the background.
Using JTextArea, I would like for the first line to be a simple text (Title of the JTextArea).
Is there a way to make the text center align on the first line?
I don't think you can do this with a simple JTextArea. You might consider switching to a JTextPane, which supports HTML markup. The Java Tutorial How to Use Editor Panes and Text Panes shows an example.
Alternatively, you can just add a JLabel above your JTextArea where you display the title text.
I have the following JTextField where I would like to change the cursor position from the middle to the TOP of the JTextField:
How do I accomplish that?
There is no such thing as a multi-line JTextField. What you posted is a regular, single-line JTextField which is simply stretched out.
If you need mutli-line text components, consider using a JTextArea or JTextPane in which you can perfectly set the cursor (caret) at the first line
Edit
Just read your comment. An editable textfield for output is just confusing to the user. At least make it non-editable, or opt for a JLabel with a Border