S
S
Stavr Strelov2020-02-23 12:29:03
PHP
Stavr Strelov, 2020-02-23 12:29:03

Java. How to format text in JTextArea and JTextField (change color, font, etc.)?

Can you please tell me everything you know about text formatting in JTextArea and JTextField !
I know that there are methods:

setBackground(Color color) //Changes the background color of the entire field for text
setForeground(Color color) //Changes the color of all text in the field

But these methods change the color of the entire field, but how to change, for example, the color specific letter? And not affect the rest?
How to change the font of a specific letter? How to change the size of a specific letter?
And another question - it is possible to make a section of text inside a JTextArea or JTextField in which the cursor cannot be placed, which cannot be changed: erase, rewrite, etc.
Many thanks and respect in advance :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Edward, 2019-06-28
@MrRadio_Spy

~^[^az]+~i
Bundled with PHP will be like this

$text = '90+3\' SGDGG p[gdsg] sadgcgbcvb';

echo preg_replace('~^[^a-z]+~i', '', $text);

D
Dmitry Derepko, 2019-06-28
@xEpozZ

What template will be for "90+3"? 2 digits, "+", digit? Or everything before "'" (single quote)?

$text = "90+3' SGDGG p[gdsg] sadgcgbcvb";

$result = preg_replace('/^[^\']+\'/', '\'', $text);

If it's static, you can use
$result = str_replace('90+3', '', $text);

A
ascherbinin82, 2020-02-23
@ascherbinin82

To do this, you need to create your own component. You can make this task easier: inherit methods responsible for input and display

A
Alexey Cheremisin, 2020-02-23
@leahch

There is JEditorPane and JTextPane, look at them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question