Suppose I have a graph composed of nodes and edges, and I want to draw it in a Swing app. I'm not a Swing programmer, but as far as I know, I see two approaches:
I've seen an application doing the first. To drag a node, drawn as a circle, the app checks what is the nearest node to the clicked point. It seems to me that this is not much efficient. Is the second approach feasible? And which one should be followed, and why?
We write and maintain JGraph
and after 10 years of doing so we still have a single flyweight renderer that's shared to draw all cells. The reason is the memory cost of a component per cell. The disadvantage is that you need to deal with refreshing and event handling yourself, but it's not that bad.
We've had the coversation many many times, always the same conclusion.
Either approach is feasible, depending on the requirements. GraphPanel
is a simple example of a single component, while JGraph
is a more flexible library that uses the flyweight pattern for efficient rendering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With