2D Swing Graphics Library for Text
The approach I've used in the past is to draw your shape with Graphics2D into one panel. Graphics2D gives you the exact placement of text and line. When you want to edit the text, ask the user to click on the text and place the JTextArea or similar in the pane where the text is when the user is editing.
a source to share
I like the answer, which suggests using the JTextArea when the user is about to edit the text, since it's simple. However, if you want truthful in-place editing while still providing your own textual content, you can explore creating your own view implementation for the JEditorPane. This gives you ready-made models and a controller for editing, allowing you to provide a presentation so you can render as accurately as possible. And with the JEditorPane.DefaultEditorKit available as a source, you have a lot of guidance on how to implement your own view.
This may be overkill for your needs, or it may give you the level of control you need.
a source to share