Take the 2-minute tour ×

The title is a bit confusing, but I will be using Java and Jframe. Basically, I want to be able to click anywhere on the form and have a "text area/box" show up (maybe use a JTextField or JTextArea ?). I want the user to be able to edit, delete and move this string around as well.

I am thinking I need an actionlistener to listen for clicks on the form. Each click will call for a new text"box" to be created. I am not sure how to make this "box" editable, deleteable, or moveable by the user though.

I need a way to store the string and co-ordinate data too. Would it be a good idea to simply extend the JTextField or JTextArea to add co-ordinate information to them? I see that swing is event based, so I need some kind of trigger to "save" the text (was thinking the enter key, but I realize I'd like the user to be able to enter multi-line strings).

Any thoughts would be appreciated. I am familiar with Java but only have a bit of experience with the UI portion.

share|improve this question
add comment

1 Answer

Instead of an ActionListener you will need a MouseListener to track clicks.

Sounds like you need an undecorated JInternalFrame with a text box in it on JDesktopPane. However, I don't think you can create an undecorated JInternalFrame, maybe start with a normal JInternalFrame with a TextBox in it and create new frames on mouse clicks on the Desktop Pane. Then see if you can make the JInternalFrame more like a Window.

Another route is a custom component that does everything you need. This is possible, just a lot more custom code.

share|improve this answer
Thanks! I kept looking and found some code to make things draggable (stackoverflow.com/questions/874360/…;. Now I just need to find a way to add the text component! –  matthieu May 9 '11 at 17:23
add comment

Your Answer


