How to add a numbered prefix on each line in JTextArea

47 Views Asked by At

I am trying to make a program that automatically adds a set prefix on each line inputted in the JTextArea

So let's say the prefix I set in code is "Step (#):", every line would be something like: Step 1: test item Step 2: test item 2 Step 3: test item 3

where the test items are inputted by the user. Preferrably the prefix is uneditable. Also curious if it was possible to automatically change the step number below incase a user makes a line break between steps.

I have tried appending the step but cant figure out how to add step 2 on line break or even auto adjust. Also tried DocumentFilter but got nowhere with it.

0

There are 0 best solutions below