For my current project I have the situation that I need an interactive element that will be drawn on a custom graphics context and allows user interaction (e.g. mouse clicks).
Since this elements will be quite complex I decided the best solution would be to use a JPanel for layouting and manually paint it and dispatch mouse and keyboard events.
Currently my plan is to:
- call setSize and setLocation on the Jpanel
- call paint with the graphic context
- Catch desired events (in this example clicks) create a new MouseEvent and pass it on with JPanel.dispatchEvent().
I suspect there will be many traps and edge cases along the way so
a.) Is this the correct approach or is it missing something fundamental? b.) Is there any existing library which could be uses?