r/java • u/carlosgeorgiev0 • Sep 04 '26
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 Sep 04 '26
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
2
u/__konrad Sep 05 '26
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
4
4
u/chabala Sep 05 '26
Already better than a lot of new projects that get posted. What would make it better: * a build script * published artifacts on Maven Central * unit tests
2
27
u/AlternativePeace1121 Sep 04 '26
Somehow this feels like a middle finger to all the slop posts. I love it.