I'm trying to create some drawing functionality, effectively very similar to MSPaint. I want to make a TextBox
tool, such that I can draw a textbox on my canvas and have a user type in it like a real textbox. Once the user clicks off of the textbox or presses escape, then I would "stroke"
the text to the GraphicsContext
.
I'm not sure how to do this. My current attempt has me using StackPane
to stack two canvases on top of each other. I let the user "draw"
a textbox with the mouse, and then I create a textbox programmatically which I am trying to pass the keyevents
into. Then when the user clicks off, I write textbox.getText()
to the GraphicsContext
. This has not been very successful. Specifically, I'm not sure how to handle special keys like BACKSPACE
and DELETE
and letting the user click to place the cursor.
I'm looking for advice on a better approach.