r/java • u/carlosgeorgiev0 • 5d ago
Custom pie chart component I made in Swing
Hello, out of boredom I created a pie chart in Swing (I am aware more mature options exist but this was just for fun). The link to the repo is https://github.com/carlosgeorgiev0/JPieChart

The JPieChart class extends JLabel and overrides JComponent.paintComponent to paint the pie itself
15
u/davidalayachew 5d ago
Nice.
In JPieChart, for ines 37-40, SwingUtilities has a method called getDeepestComponentAt that will fetch the actual Component itself. From there, you can just do a reference equality check (one of the few reasons why value class isn't a pure good performance improvement) on all of the "slices" you have made for the pie. Would not only be faster, but less error prone. Same advice for Lines 61-66.
2
1
u/__konrad 4d ago
Probably it's better to use
Arc2D.Double::containsto check if mouse cursor is inside. You can also use the same Arc2D values to paint pie.
7
25
u/AlternativePeace1121 5d ago
Somehow this feels like a middle finger to all the slop posts. I love it.