I am making a paint program and I'm coming across some trouble figuring out how to make a text tool. What I want to do is click and drag to make a textbox appear on the canvas. The problem is that I don't want this to just be a JTextComponent floating over my canvas component. That causes issues with the border flickering when I move it and parts of my cursor looking like they're under the textbox when my mouse is right next to it.
What I was going to do was create a JTextArea and then fire mouseEvents at is based on my mouse's location relative to the textbox on the canvas. The one on the canvas would really just be a painted representation (using .getGraphics()) of the actual JTextArea that I haven't added to any component. The problem with this is that you can't call .getGraphics() unless the component is displayed on the screen.
I'm trying to avoid recreating the entire JTextComponent code just for something like this that seems like it should be simple.
Does anyone have any solutions to this problem or alternate ideas?